1
我在做一個項目:使用AsyncFileUpload控制上傳文件並將其存儲
Front end - Visual Studio 2010
Technology : C#
Back end - Sql Server 2005
我想上傳使用AsyncFileUpload控制文件,並存儲到「〜/圖片/」文件夾中。
腳本:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server"
onuploadedcomplete="AsyncFileUpload1_UploadedComplete"/>
</ContentTemplate>
代碼背後:
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if (AsyncFileUpload1.HasFile)
{
AsyncFileUpload1.SaveAs("~/Image/" + AsyncFileUpload1.FileName);
Label2.Text = "Recieved " + AsyncFileUpload1.FileName + " Content Type" + AsyncFileUpload1.PostedFile.ContentType;
}
}
但每次叫其顯示運行時錯誤:
The SaveAs method is configured to require a rooted path, and the path '~\Image\Filename.jpg' is not rooted.
我可以知道錯誤及其SOLU灰。
由於提前,
尼基爾
這是[確切的重複](http://stackoverflow.com/questions/1350977/the-saveas-method-is-configured-to-require-a-rooted-path-and-the-path -圖片) –