如何下载扩展名为“.jdf”的文件在ASP.NET C#中? [英] How to download files with extension ".jdf" in ASP.NET C#?

查看:92
本文介绍了如何下载扩展名为“.jdf”的文件在ASP.NET C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用web client从服务器下载格式为.jdf的文件。对于pdf文件可以正常工作但是对于JDF文件会抛出错误。







这是我的代码:

I am trying to download a file with format ".jdf" from the server using web client.it works fine for pdf files but throws error for JDF files.



here is my code:

WebClient myWebClient = new WebClient();




myWebClient.DownloadFile(remoteUri, fileName);





错误是



error is

The remote server returned an error: (404) Not Found.



状态是ProtocolError。



有谁知道如何解决这个问题?

服务器中存在所有文件。



我尝试过:



尝试了其他方法:


status is ProtocolError.

Does any one know how to solve this?
All the files exist in the server.

What I have tried:

tried other method :

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition",
                   "attachment; filename=" + remoteUri + ";");
response.TransmitFile(remoteUri);
response.Flush();
response.End();



它输入错误为不是有效的虚拟路径


it threw an error as "Not a valid virtual path"

推荐答案

默认情况下,IIS不会提供没有配置MIME类型的静态文件。您需要为 .jdf 扩展名配置MIME类型:

添加静态内容MIME映射< mimeMap> | Microsoft Docs [ ^ ]
By default, IIS will not serve static files which do not have a MIME type configured. You need to configure the MIME type for the .jdf extension:
Adding Static Content MIME Mappings <mimeMap> | Microsoft Docs[^]


Quote:

远程服务器返回错误:(404)Not找到。

The remote server returned an error: (404) Not Found.



根据错误消息,服务器会告诉您所请求的文件不存在。

检查文件是否在您认为的位置,检查路径和名称。

请确保您在正确的位置申请。

制作一个html页面,其中包含指向该文件的直接链接并尝试下载。



我们看不到您的服务器,所以只提供有关尝试的建议。


As per error message, the server tells you that the file you requested does not exist.
Check that the file is where you think it is, check path and name.
Make sure you request it in correct place.
Make an html page with direct link to the file and try to download it.

We can't see your server, so only advice on things to try.


这篇关于如何下载扩展名为“.jdf”的文件在ASP.NET C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆