我試圖做一個編輯的個人資料頁..ASP.net C#中的FileUpload和在pageLoad的
凡在頁面加載,用戶從數據庫及其顯示的讀取數據。
我使用的保存按鈕點擊一個文件上傳..
<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? –
沒有嘗試捕捉頁面加載...只有當(!Page.IsPostBack) – Rifshan
你能發佈page_load()和editprofile_save按鈕的完整代碼塊嗎? –