C# 2.0 发生错误:System.NotSupportedException
我有一个网站,已经运行了近6个月。网站上有一个部分,用户最多可以上传5张房产图片。对于每10个用户,我有一个用户会遇到System.NotSupportedException问题。由于这并不是发生在所有用户身上,而且我似乎无法重现这个错误,所以我不确定如何找到解决方案。查看错误消息,我认为这可能与他们机器上的网络配置有关,但我不是100%确定。如有任何想法/建议,将不胜感激 下面是上传图像的代码C# 2.0 发生错误:System.NotSupportedException,c#-2.0,C# 2.0,我有一个网站,已经运行了近6个月。网站上有一个部分,用户最多可以上传5张房产图片。对于每10个用户,我有一个用户会遇到System.NotSupportedException问题。由于这并不是发生在所有用户身上,而且我似乎无法重现这个错误,所以我不确定如何找到解决方案。查看错误消息,我认为这可能与他们机器上的网络配置有关,但我不是100%确定。如有任何想法/建议,将不胜感激 下面是上传图像的代码 private void UploadPhotos() { Stream objStream
private void UploadPhotos()
{
Stream objStream;
HttpFileCollection uploads = HttpContext.Current.Request.Files;
for (int i = 0; i < uploads.Count; i++)
{
if (uploads[i].ContentLength == 0)
continue;
try
{
string fileName = Path.Combine(image + "-" + i.ToString(), uploads[i].FileName);
//uploads[i].SaveAs(Server.MapPath("~/ExtendedImages/") + fileName);
using (new Impersonator("serverusername", @"serverlocation", "serverpassword!"))
{
try
{
uploads[i].SaveAs(@"serverlocation" + fileName);
}
catch (NotSupportedException ex)
{
uploads[i].SaveAs(Server.MapPath("~/ExtendedImages/") + fileName);
}
}
//uploads[i].SaveAs(Server.MapPath("~/ExtendedImages/") + fileName);
byte[] myimage = new byte[uploads[i].ContentLength];
objStream = uploads[i].InputStream;
objStream.Read(myimage, 0, uploads[i].ContentLength);
System.Drawing.Image Image1;
System.Drawing.Image Thumbnail;
Image1 = new Bitmap(objStream);
Image1.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
Image1.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
int NewWidth = 380;
int MaxHeight = 400;
if (Image1.Width <= NewWidth)
{
NewWidth = Image1.Width;
}
int NewHeight = Image1.Height * NewWidth / Image1.Width;
if (NewHeight > MaxHeight)
{
NewWidth = Image1.Width * MaxHeight / Image1.Height;
NewHeight = MaxHeight;
}
System.Drawing.Image NewImage = Image1.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);
Thumbnail = Image1.GetThumbnailImage(100, 80, null, IntPtr.Zero);
MemoryStream ms = new MemoryStream();
MemoryStream ms2 = new MemoryStream();
Thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
NewImage.Save(ms2, System.Drawing.Imaging.ImageFormat.Jpeg);
Photos photos = new Photos();
photos.ID = HomeTourSession.HometourName;
photos.AdId = (int)Session["adid"];
photos.FullPhoto = ms2.ToArray();
photos.ThumbnailPhoto = ms.ToArray();
photos.AlternateText = "";
photos.Insert();
}
catch (Exception exp)
{
throw new Exception("Error occured: " + exp);
}
}
}
private void UploadPhotos()
{
流对象流;
HttpFileCollection uploads=HttpContext.Current.Request.Files;
对于(int i=0;i
这是一些用户正在得到的错误
发生错误:System.NotSupportedException:给定路径的格式
不支持。在
System.Security.Util.StringExpressionSet.CanonicalizePath(字符串路径,
布尔值(完整路径)
System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[]
str,Boolean needFullPath)位于
System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess
access,AccessControlActions控件,字符串[]路径列表,布尔值
检查重复项、布尔需要完整路径、布尔复制路径列表)位于
System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess
access,AccessControlActions控件,字符串[]路径列表,布尔值
checkForDuplicates,Boolean needFullPath)位于
System.IO.FileStream.Init(字符串路径、文件模式、文件访问
访问、Int32权限、布尔用户权限、文件共享共享、Int32
缓冲区大小,文件选项,安全属性,字符串
msgPath,Boolean bFromProxy)位于System.IO.FileStream..ctor(字符串
路径、文件模式、文件访问访问、文件共享共享、Int32
bufferSize、FileOptions、字符串msgPath、布尔bFromProxy)
在System.IO.FileStream..ctor(字符串路径,文件模式)处
System.Web.HttpPostedFile.SaveAs(字符串文件名)位于
记录传递给SaveAs()的路径名,这样您就可以知道出了什么问题。并始终使用Path.Combine()而不是
+
捕获异常后,是否可以将它们重定向到错误页?这个代码可能有用,不是吗?对不起,这是代码。catch(NotSupportedException ex){uploads[i].SaveAs(Server.MapPath(“~/ExtendedImages/”)+fileName);Response.Redirect(“~/Register/RegistrationErrorPage.aspx”,false);}