【发布时间】:2015-01-02 20:42:10
【问题描述】:
我正在尝试编辑个人资料页面..
在页面加载时,用户从数据库中读取数据并显示。
我在点击保存按钮时使用文件上传..
<asp:Label ID="Label17" runat="server" Text="Logo"></asp:Label>
<div id="photo" >
<asp:Image ID="Image1" runat="server" Height="155px" Width="173px" />
<asp:FileUpload ID="FileUpload1" runat="server" Width="220px " />
</div>
C#
System.IO.FileInfo file = new System.IO.FileInfo(FileUpload1.PostedFile.FileName);
string fname = file.Name.Remove((file.Name.Length - file.Extension.Length));
fname = fname + Guid.NewGuid().ToString("N") + file.Extension;
string photo = "";
photo = fname;
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath("~/images/dp/" + fname));
Image1.ImageUrl = "~/images/dp/" + fname;
}
else
{
// saved.InnerText = "Please Select Employee Photo";
}
页面加载功能:
Image1.ImageUrl = "~/images/dp/" + myReader3["s_dp"].ToString();
嗯,上传功能正常,保存到数据库中,图片加载到下一页加载正常...
问题是,如果我在不选择新文件的情况下单击配置文件保存按钮,则会出现错误。如果选择了文件,它可以工作并保存在数据库中。
但是例如,如果我要编辑名称而不对文件上传区域做任何事情,然后单击保存按钮...弹出错误...
The path is not of a legal form.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: The path is not of a legal form.
Source Error:
Line 111: string sid;
Line 112: sid = Request.QueryString["SID"].ToString();
Line 113: System.IO.FileInfo file = new System.IO.FileInfo(FileUpload1.PostedFile.FileName);
Line 114: string fname = file.Name.Remove((file.Name.Length - file.Extension.Length));
Line 115: fname = fname + Guid.NewGuid().ToString("N") + file.Extension;
Source File: c:\Users\User\Documents\Visual Studio 2010\WebSites\HireMe\admin\editseeker.aspx.cs Line: 113
任何形式的帮助都将不胜感激,希望我能清楚地说明我的问题..
【问题讨论】:
-
那么 page_load IsPostback 或 !IsPostback 呢?请发送完整的 page_load 代码。你使用 try-catch 了吗?
-
No try catch in pageload... 仅当 (!Page.IsPostBack)
-
能否贴出page_load()和editprofile_save按钮的完整代码块?
标签: c# asp.net file-upload