C# 使用FileStream和FileUpload添加图像
我正在尝试将图像文件上载到Server.MapPath(“~/Pictures”)。我相信文件上传已经成功了。FileStream未将所选图像置于“Pictures/”位置C# 使用FileStream和FileUpload添加图像,c#,filestream,C#,Filestream,我正在尝试将图像文件上载到Server.MapPath(“~/Pictures”)。我相信文件上传已经成功了。FileStream未将所选图像置于“Pictures/”位置 你检查权限了吗?如果没有,您应该授予该目录的权限。如何授予权限?在Web.Config?中,如果您正在使用Web应用程序,则应授予IIS_IUSRS(用于IIS)文件CRUD操作的权限。您可以使用windows文件资源管理器执行此操作。右键单击文件夹->属性->安全->编辑->添加->前进->查找->双击IIS\u IUR并
你检查权限了吗?如果没有,您应该授予该目录的权限。如何授予权限?在Web.Config?中,如果您正在使用Web应用程序,则应授予IIS_IUSRS(用于IIS)文件CRUD操作的权限。您可以使用windows文件资源管理器执行此操作。右键单击文件夹->属性->安全->编辑->添加->前进->查找->双击IIS\u IUR并继续。添加IIS\u IUR后没有发生任何事情。只是在IIS Express中工作。
if (FileUpload1.HasFile)
{
string imagename = System.IO.Path.GetFileName(FileUpload1.FileName);
string ext = System.IO.Path.GetExtension(FileUpload1.FileName);
string imagefile = Server.MapPath("Pictures/" + imagename + ext);
byte[] Image = null;
if (ext == ".jpg" | ext == ".gif" | ext == ".png" | ext == ".bmp")
{
Image = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile UploadedImage = FileUpload1.PostedFile;
UploadedImage.InputStream.Read(Image, 0, (int)FileUpload1.PostedFile.ContentLength);
int numBytesToRead = Image.Length;
try
{
using (FileStream fsNew = new FileStream(imagefile, FileMode.Create, FileAccess.Write))
{
fsNew.Write(Image, 0, numBytesToRead);
}
}
catch (FileNotFoundException ioEx)
{
Label100.Text = "Filestream Add Pictures: " + ioEx.ToString();
}
}