English 中文(简体)
ASP - Prompt Save file dialog from thestream author
原标题:ASP - Prompt save file dialog from streamwriter
  • 时间:2010-07-29 20:29:35
  •  标签:
  • c#
  • asp.net

目前,我有桌面文本档案,在伙伴关系中,我怎么能为用户发出一个文件,以拯救方言? 其结果从流层中推测为“结果”:

StreamWriter FileWriter = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "file.txt"));

                FileWriter.Write(result);

                FileWriter.Close();
最佳回答
String FileName = filename;
String FilePath = filepath;
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
response.TransmitFile(FilePath + FileName);
response.Flush();
response.End();
问题回答
Response.AppendHeader("Content-Disposition", "attachment");
StreamWriter FileWriter = new StreamWriter(Response.OutputStream);
FileWriter.Write(result);

我曾尝试过这部法律,但也许你需要放弃对)的号召,因为它将试图处置这些术语。 否则,你就应当使用<条码>,使用。 如果存在问题,则直接用<代码>Write方法或使用<代码>MemoryStream书写。

我的一位评论就是一例。

    protected void Page_Load(object sender, EventArgs e)
{
    string tempFileName = Request["tempFileName"];  // the temp file to stream
    string attachFileName = Request["attachFileName"];  // the default name for the attached file

    System.IO.FileInfo file = new System.IO.FileInfo(Path.GetTempPath() + tempFileName);
    if (!file.Exists)
    {
        pFileNotFound.Visible = true;
        lblFileName.Text = tempFileName;
    }
    else
    {
        // clear the current output content from the buffer
        Response.Clear();

        // add the header that specifies the default filename for the 
        // Download/SaveAs dialog 
        Response.AddHeader("Content-Disposition", "attachment; filename=" + attachFileName);

        // add the header that specifies the file size, so that the browser
        // can show the download progress
        Response.AddHeader("Content-Length", file.Length.ToString());

        // specify that the response is a stream that cannot be read by the
        // client and must be downloaded
        Response.ContentType = "application/octet-stream";
        // send the file stream to the client
        Response.WriteFile(file.FullName);
    }        
}
string path = Server.MapPath(your application path);
WebClient client = new WebClient();            
byte[] data = client.DownloadData(new Uri(path));
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", "aspnet.pdf"));
Response.OutputStream.Write(data, 0, data.Length);

try this code.. its helpful

Don t 知道它是否仍然开放,只是帮助他人

简言之,它应当努力促使用户为开立或保存系统档案而开辩。

byte[] bytesPDF = System.IO.File.ReadAllBytes(@"C:sample.pdf");

        if (bytesPDF != null)
        {

            Response.AddHeader("content-disposition", "attachment;filename= DownloadSample.pdf");
            Response.ContentType = "application/octectstream";
            Response.BinaryWrite(bytesPDF);
            Response.End();
        }

如果我正确理解你的话,你首先拥有1级(台站式)的仪器,用C#向用户档案系统保存一个文件。 现在,你正试图与你一道向两层次过渡。 C#代码在服务器级运行,用户浏览器代表另一个层次。 在服务器上的C#中,你无法直接向浏览器用户档案系统提交文件。

尽管如此,你需要做的是向吉大港定居人士协会的复函发送文件,其中含有诸如申请/游览等内容。 您是否实际使用过协会或协会。 NET? 如果后一种情况是,你可以通过各种手段进入反应过程,但首先使用反应物体(可从网页上查阅,也可通过HttpContext查阅)。 Current.Response。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签