Asp.net网络服务文件下载 [英] Asp.net web service file download

查看:159
本文介绍了Asp.net网络服务文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用ASP.net Webservice生成PDF文件并将其下载到客户端计算机。



但奇怪的是,不是将文件保存到用户计算机下载文件夹,Web Service将文件保存到承载ASP.net Web应用程序的IIS服务器DefaultAppPool \ Download文件夹。



这是我当前生成文件夹路径的文件夹



  string  status =  ; 
string filename = File _
string sourcepath = < /跨度>;
string destinationpath = ;
string baseUrl = http:// SERVERPATH / MyApp的/;

filename = filename + _ + DateTime.Now.ToLongTimeString( ).Replace( - )。替换( - )+ 。pdf;
sourcepath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings [ _ baseTempPDFPath] + filename);
destinationpath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+ \\Downloads\\\ \\ + filename;
string DocContent = ;





以下代码行生成错误的路径,这不是我想要的。

< pre lang =c#> destinationpath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+ \\Downloads \\ + filename;



我想要的是C:\ Users \ProfileName \Downloads \

我想将动态生成的PDF保存到此路径。



或者有没有办法将PDF下载到用户计算机



我试过这段代码而且不起作用



 HttpContext.Current.Response.BinaryWrite(outPdfBuffer) ); 
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.SuppressContent = true ;
HttpContext.Current.ApplicationInstance.CompleteRequest();





任何解决方案



我尝试过:



我已经粘贴了我目前在Web服务中使用的代码。我正在使用EVOPDF生成PDF文件。

解决方案

您的代码在服务器上运行,因此当您要求下载文件夹时,您将获得服务器上的文件夹运行代码的帐户,默认应用程序池的文件夹。



您无法指定文件保存的路径,您只能声明其filename和用户将其保存在他们想要的位置。您也不能直接保存到用户的文件系统。


I am currently using a ASP.net Webservice to generate and downlaod PDF file to the clients computer.

Whats weird though is that instead of saving the file to the users computer download folder the Web Service saves the file to the IIS Server DefaultAppPool\Download folder on which the ASP.net web application is hosted onto.

This is my current folder which to generate folder paths

string status = "";
string filename = "File_"
string sourcepath = "";
string destinationpath = "";
string baseUrl = "http://serverPath/MyApp/";

filename = filename + "_" + DateTime.Now.ToLongTimeString().Replace(":", "-").Replace(".", "-") + ".pdf";
sourcepath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["_baseTempPDFPath"] + filename);
destinationpath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads\\" + filename;
string DocContent = "";



This below line of code generate a wrong path which is not intended by me.

destinationpath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads\\" + filename;


What i want is C:\Users\ProfileName\Downloads\
I want to save the dynamically generated PDF to this path.

OR Is there a way to download the PDF to users computer

I tried this code and it does not work

HttpContext.Current.Response.BinaryWrite(outPdfBuffer);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();



Any solutions

What I have tried:

I have pasted the code above which i am currently using in the Web Service. I am using EVOPDF to generate the PDF file.

解决方案

Your code is running on the server so when you ask for the Downloads folder you get the folder on the server of the account the code is running under, ergo the default app pool's folder.

You can't dictate the path that the file is saved as, you can only state its filename and the user saves it where they want to. Neither can you save directly to the user's file system either.


这篇关于Asp.net网络服务文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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