[英]File Uploading to Server
我正在Asp.Net
工作,我想將文件上傳到服務器,它向我顯示錯誤
SaveAs
方法配置為需要有根目錄的路徑,而路徑〜/ 192.zzz.zzz.z / CaheadServices / ImagesNIINIR.jpg'則沒有根目錄。
這是我的代碼
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
fup.SaveAs("~/192.zzz.zzz.z/CaheadServices/Images" + fup.FileName);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
請幫幫我。
您正在嘗試將文件保存在共享路徑上。 並使用相對URL,該URL不得存在於您的應用程序的文件夾中。 所以你的路徑應該像下面的例子
String pathAndFile = "\\\\Server\\Folder\\";
FileUpload1.SaveAs(pathAndFile);
同樣,因為您的代碼將在IIS
,所以您必須向IUSER
提供權限以在共享位置上載文件。
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
fup.SaveAs(Server.MapPath("~/192.zzz.zzz.z/CaheadServices/Images" + fup.FileName));
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.