Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Filestream image to folder.
C#
string imgname = "Pictures/" + pic1.jpg;
using (System.IO.FileStream fs = New System.IO.FileStream(Server.MapPath("imgname"), System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read, 8, System.IO.FileOptions.None)))
    {
        Byte[] byte1 = System.IO.File.ReadAllBytes(open.FileName);                                              
        fs.Write(byte1, 0, byte1.Length);
        fs.Flush();
        fs.Close();
    }

Error in "open.FileName"

What I have tried:

Tried different Byte[] byte1 scenerios. None worked for an image.
Posted
Updated 30-Jun-17 6:12am
v2

1 solution

Well... you are using Server.MapPath, so this is a web app. We don't know what "open" is - but the chances are it's a FileUpload control (because if you aren't getting it from the client, then it's probably on the same server, so File.Copy is more efficient) and we have no idea what the error message is.

But if it is a FileUpload control, then the FileName property tells you what it is called on the client, but you can't read the file - you have to get the file from the control with the SaveFile method or the FileBytes property. Since you are trying to write the file, I'd suggest the SaveFile method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900