I've uploaded a file with the FileUpload control. I've got the path and everything and I would like to save the image to the server. I don't want to use the SaveAs() method. I wonder, is there a way to save the file with using-statement?
Asked
Active
Viewed 7,790 times
-2
-
Please try to elaborate more on why do you want to do so – DanielV May 19 '15 at 15:26
4 Answers
0
Check out http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx. You should be able to stream the data into a new file created in permanent storage. Or just do a copy operation from the tmp path you said you already have.
http://msdn.microsoft.com/en-us/library/system.io.file.copy(v=vs.71).aspx

j_mcnally
- 6,928
- 2
- 31
- 46
0
You can use StreamReader to read the file from file upload and use StreamWriter class to write it to your server with Server.MapPath() function(ur server absolute path)

Prabhavith
- 458
- 1
- 4
- 15
0
You have FileUpload.FileBytes method which returns array of bytes of uploaded file or use FileUpload.PostedFile.InputStream
property to get stream of uploaded file.

KV Prajapati
- 93,659
- 19
- 148
- 186
0
Try this
string pilepath = Server.MapPath(".") +"\\"+ fl.FileName;
System.IO.File.WriteAllBytes(pilepath, fl.FileBytes);
fl.FileBytes Gets an array of the bytes in a file that is specified by using a FileUpload control.

Sanjay Goswami
- 1,386
- 6
- 13