[英]“Server Error in '/' Application. Could not find a part of the path” in ASP .NET C#
我創建了一個ListView
並在名為lnkDownload
內部創建了一個LinkButton
來下載圖像。 我的代碼在localhost上工作正常,但在服務器上顯示錯誤。
源代碼 :
<asp:ListView ID="ListViewSizePrice" OnItemCommand="ListViewSizePrice_ItemCommand" runat="server">
<ItemTemplate>
<tr>
<td><%#Eval("Size") %></td>
<td><asp:RadioButton ID="RadioButtonRawYes" GroupName="RawFile" ClientIDMode="Static" CssClass="form-control" Checked="true" Text=" Yes" runat="server" Width="70px" />
<asp:RadioButton ID="RadioButtonRawNo" GroupName="RawFile" ClientIDMode="Static" CssClass="form-control" Checked="false" Text=" No" runat="server" Width="70px" />
</td>
<td><%#Eval("ImageFormat") %></td>
<td>
<asp:HiddenField ID="HiddenFieldImageUrl" Value='<%# Eval("ImageURL") %>' runat="server" Visible="false" />
<asp:LinkButton ID="lnkDownload" Text = "Download" CommandName="imageDownload" runat="server"></asp:LinkButton></td>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
代碼隱藏
protected void ListViewSizePrice_ItemCommand(object
sender,ListViewCommandEventArgs e)
{
if (e.CommandName == "imageDownload")
{
string ImageUrl = ((HiddenField)e.Item.FindControl("HiddenFieldImageUrl")).Value;
string FileExtension = Path.GetExtension(ImageUrl);
if (FileExtension == ".rar" || FileExtension == ".RAR")
{
Response.ContentType = "application/rar";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(ImageUrl));
string absImageUrl = Server.MapPath("Admin/" + ImageUrl);
//absImageUrl.Replace("\\", "\\");
Response.TransmitFile(absImageUrl);
Response.End();
}
else
{
Response.Redirect(Request.Url.AbsoluteUri);
}
}
}
此代碼在localhost上完美運行。 但在服務器上它顯示以下錯誤
Server Error in '/' Application.
Could not find a part of the path 'C:\Inetpub\vhosts\basiyan.co.in\basiyan.com\Admin\ImagesUploads\Admin 16-05-2017\1\Image 10 X 10\10 X 10.rar'.
檢查文件路徑
將所需文件放在“發布”中
嘗試動態獲取文件路徑,而不是將其存儲在隱藏字段中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.