protected void btnUpload_Click(object sender, EventArgs e)
{
if ((FileUpload1.PostedFile.FileName == "" && FileUpload2.PostedFile.FileName == "") && FileUpload3.PostedFile.FileName == "")
{
this.lblInformation.Text = "请选择文件!";
}
else
{
HttpFileCollection myfiles = Request.Files;
for (int i = 0; i < myfiles.Count; i++)
{
HttpPostedFile mypost = myfiles[i];
try
{
if (mypost.ContentLength > 0)
{
string filepath = mypost.FileName;
string filename = filepath.Substring(filepath.LastIndexOf("//") + 1);
string serverpath = Server.MapPath("images/") + filename;
mypost.SaveAs(serverpath);
this.lblInformation.Text = "上传成功!";
}
}
catch (Exception error)
{
this.lblInformation.Text = "上传发生错误!原因:" + error.ToString();
} } } }具体错误:
上传发生错误!原因:System.NotSupportedException: 不支持给定路径的格式。 在 System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) 在 System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) 在 System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) 在 System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath) 在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) 在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) 在 System.IO.FileStream..ctor(String path, FileMode mode) 在 System.Web.HttpPostedFile.SaveAs(String filename) 在 Cal_calUpload.btnUpload_Click(Object sender, EventArgs e)
{
if ((FileUpload1.PostedFile.FileName == "" && FileUpload2.PostedFile.FileName == "") && FileUpload3.PostedFile.FileName == "")
{
this.lblInformation.Text = "请选择文件!";
}
else
{
HttpFileCollection myfiles = Request.Files;
for (int i = 0; i < myfiles.Count; i++)
{
HttpPostedFile mypost = myfiles[i];
try
{
if (mypost.ContentLength > 0)
{
string filepath = mypost.FileName;
string filename = filepath.Substring(filepath.LastIndexOf("//") + 1);
string serverpath = Server.MapPath("images/") + filename;
mypost.SaveAs(serverpath);
this.lblInformation.Text = "上传成功!";
}
}
catch (Exception error)
{
this.lblInformation.Text = "上传发生错误!原因:" + error.ToString();
} } } }具体错误:
上传发生错误!原因:System.NotSupportedException: 不支持给定路径的格式。 在 System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) 在 System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) 在 System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) 在 System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath) 在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) 在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) 在 System.IO.FileStream..ctor(String path, FileMode mode) 在 System.Web.HttpPostedFile.SaveAs(String filename) 在 Cal_calUpload.btnUpload_Click(Object sender, EventArgs e)
解决方案 »
- 初学ASP.NET的简单问题。高手帮忙看下
- asp.net 登录验证
- asp.net 代码实现解析 aspx 代码的问题
- (ASP.NET)怎样在运行时动态更改数据访问层(DAL)的TableAdapter的ConnectionString?
- 应该添加什么引用?自写savedialog的问题
- VS2008发布网站的问题~急急急!!!
- 关于构造函数,请高手给讲讲,有个地方不明白!!
- 郁闷网站被黑,所有文字字段被加入</title></</title></pre>"><script src=http://1.hao929.cn/ads.js></script><!--
- 回发或回调参数无效
- asp.net初学问题
- 天气网插件加载很慢,影响页面打开
- 插入数据编号问题
打个断点看看这个长啥样。。
string serverpath = Server.MapPath("images/"+ filename+"");
mypost.SaveAs(serverpath);