I have the path of a file I would like to upload but the method takes the file input Stream.
Can anyone tell me how I can get the input stream from the path?
I have upload files before when using a open file dialog and that takes the file in as a file input Stream, but the new section of my webpage the user does not select the file, I have to go grab it with code, but I know its file path.
public string uploadfile(string token, string filenameP, DateTime modDate, HttpPostedFileBase file)
{
//... code to upload file
}
I would like something like the ClassLoader like in java.
See this question here.
https://stackoverflow.com/a/793216/1479146
In C#, the way to get a Stream (be it for input or for output): use a derived class from Stream, e.g. new FileStream(inputPath, FileMode.Open)
You can use StreamWrite or StreamReader class for this purpose:
// for reading the file
using (StreamReader sr = new StreamReader(filenameP))
{
//...
}
// for writing the file
using (StreamWriter sw = new StreamWriter(filenameP))
{
//...
}
Reference: http://msdn.microsoft.com/en-us/library/f2ke0fzy.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With