简体   繁体   English

无法在已发布的网站中查看本地驱动器文件

[英]Unable to view Local Drive Files in published Website

I want to view files in local drive in computer. 我想查看计算机本地驱动器中的文件。 The solution worked on my local computer but when i published website it doesn't work.I have listed files successfully but when i try to download file. 该解决方案可以在我的本地计算机上使用,但是当我发布网站时它不起作用。我已成功列出文件,但是当我尝试下载文件时。 it gives error. 它给出了错误。 It worked perfectly on my Local pc but when i published it on IIS and try to view file it gives error. 它在我的本地PC上运行完美,但是当我在IIS上发布它并尝试查看文件时,它给出了错误。

    Response.ContentType = "text/plain";
    Response.AddHeader("Content-Disposition", "inline;filename=" + fileName);
    Response.TransmitFile(Server.MapPath(Path.Combine("~/E:/NewFolder/", fileName)));
    Response.End();

Error: 错误:

The given path's format is not supported. 
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.NotSupportedException: The given path's format is not supported.

Source Error: 


Line 28:         Response.ContentType = "text/plain";
Line 29:         Response.AddHeader("Content-Disposition", "inline;filename=" + fileName);
Line 30:         Response.TransmitFile(Server.MapPath(Path.Combine("~/E:/NewC/", fileName)));
Line 31:         Response.End();
Line 32:         }


Source File: E:\New folder\ViewFiles\ViewFiles\Default2.aspx.cs    Line: 30 

Stack Trace: 


[NotSupportedException: The given path's format is not supported.]
   System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) +12651960
   System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) +165
   System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) +112
   System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) +38
   System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path) +92
   System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) +549
   System.Web.HttpServerUtility.MapPath(String path) +234
   ViewFiles.Default2.Page_Load(Object sender, EventArgs e) in E:\New folder\ViewFiles\ViewFiles\Default2.aspx.cs:30
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064

You are giving the physical path of file in Server.MapPath whereas you have to give the virtual path. 您需要在Server.MapPath中提供文件的物理路径,而必须提供虚拟路径。 This is what MSDN says about Server.MapPath Specifies the relative or virtual path to map to a physical direct 这就是MSDN关于Server.MapPath的说法,它指定要映射到物理直接目录的相对或虚拟路径

If the path is outside the hosted website you can make virtual directory of the folder, containing the files you want to transfer, inside the website you have. 如果路径在托管网站外部,则可以在您拥有的网站内部建立包含要传输文件的文件夹的虚拟目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM