簡體   English   中英

“'''應用程序中的服務器錯誤。 無法在ASP .NET C#中找到路徑的一部分

[英]“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="&nbsp;&nbsp;&nbsp;Yes" runat="server" Width="70px" />
                <asp:RadioButton ID="RadioButtonRawNo" GroupName="RawFile" ClientIDMode="Static" CssClass="form-control" Checked="false" Text="&nbsp;&nbsp;&nbsp;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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM