Why I see red line under this statement

SaeedP

Well-known member
Joined
Oct 21, 2020
Messages
99
Programming Experience
3-5
Hello,

When I want to use these lines I encounter a red line under seek and copy to. And

Warns me up "Are you missing a directive"?

C#:
  var state = _instaApi.GetStateDataAsString();
                
    
             using (var fileStream = File.Create(stateFile))
             {
                 state.Seek(0, SeekOrigin.Begin);
                 state.CopyTo(fileStream);
             }

What should I do?

regards
 
Because GetStateDataAsString() returns a string. string does not have any methods called Seek() or CopyTo(). The Intellisense suggestion about directives should after the errors that should have been shown first. The directives question is just in case you need to use a directive to include another assembly which may have some extension methods for string which might have those methods. But really it's just VS2019 guessing. It doesn't know that you are screwing up royally and trying to treat a string as if it were a Stream.

You should instead save text to that file:
 
In your case, you have one string that you want to write to a file and you're not using async/await already so File.WriteAllText would be the way to go.
You mean this code:



C#:
var state = _instaApi.GetStateDataAsString();

            File.WriteAllText(stateFile.txt, state);


Is it correct?


Should I change
C#:
const string stateFile = "state.bin";

to:
C#:
const string stateFile = "state.txt";
 
Last edited:
All you need is line 6. You do not need to create a stream that you don't use any way. Stop and think about it.

As for the file extension. It usually helps if you use as file extension to help users know what is in a file or its intended use, but there is no hard and fast rule that requires a file extension match it's contents. Some examples: a screensaver is simply a DLL that just has .SCR file extension; XML and JSON files were originally designed to be plain text files, yet they have special .XML and .JSON file extensions; .REG files are essentially just .INI files; and .INI files are just text files; etc.

Anyway, to answer your question about the filename, I would recommend naming it "please steal my Instagram Username and Password.json"
 
All you need is line 6. You do not need to create a stream that you don't use any way. Stop and think about it.

As for the file extension. It usually helps if you use as file extension to help users know what is in a file or its intended use, but there is no hard and fast rule that requires a file extension match it's contents. Some examples: a screensaver is simply a DLL that just has .SCR file extension; XML and JSON files were originally designed to be plain text files, yet they have special .XML and .JSON file extensions; .REG files are essentially just .INI files; and .INI files are just text files; etc.

Anyway, to answer your question about the filename, I would recommend naming it "please steal my Instagram Username and Password.json"

😉

Do You mean
C#:
 state.Seek(0, SeekOrigin.Begin);
?

So what is the definition of the state?

Please clarify number six.

May I be wrong?

Can I use a local variable instead of writing the .bin file to blazor??
 
See your post #4. Line #6 of the first chunk of code.
 
If you have multiple web front ends, how will the value of a local variable, or otherwise, get passed from one machine to another machine?

If you have a single web front end, how will the value of a local variable survive when the scope on which the variable is it was declared is exited?
 
Sorry, can you copy and paste the code here?

I couldn't understand what you mean. Please explain more.

Do you say I use a local variable?
 
C#:
File.WriteAllText(stateFile.txt
 
Do you say I use a local variable?
I'm saying that you need to think about it. How will you make it work with a local variable? Personally, I don't see a way for it to work.

A class variable in a singleton, maybe if you have one and only one web front end, and if you have one and only one user ever logging in.

A class variable in a class that instantiated per user session will likely work if and only if you have a single web front end.
 
My idea is that you should use the proper InstaGram API where this becomes a non-issue.
 
I see some write operations being described as available here:

There is a reason why they restrict non Business users from some specific operations... To get revenue and user profile behaviors by forcing the user to use the app. Recall the recent banning of a user/developer who came up with a way to automate unfollowing in FaceBook.
 
Back
Top Bottom