Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I try to open a word document with c#.
When I open the document, the page is blocked after.

Here is the code :

HttpContext.Current.Response.Write(temp);
//HttpContext.Current.Response.End();

//HttpContext.Current.Response.Flush();

//HttpContext.Current.Response.Write(sw.ToString());
//HttpContext.Current.Response.clear();
//HttpContext.Current.Response.End();
//HttpContext.Current.Response.SuppressContent = true;
//HttpContext.Current.Response.Close();
//Response.Redirect(Page.Request.Url.AbsolutePath.Substring(0, Page.Request.Url.AbsolutePath.LastIndexOf("/")) + "/PIEditor.aspx?PostID=" + Request.Params["PostID"], true);`
//HttpContext.Current.Response.End();

As you see, I tried different options but without result, the window for opening or saving the document is displayed but I can't click on any buttons the page after. It looks like it is deactivated or stopped.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
283 views
Welcome To Ask or Share your Answers For Others

1 Answer

you can try GemBox.Document component to export Word document from ASP.NET application, if that is what you are trying to do.

Here is a sample C# code that should go in ASPX page code behind:

// Create a new empty document.
DocumentModel document = new DocumentModel();

// Add document content.
document.Sections.Add(new Section(document, new Paragraph(document, "Hello World!")));

// Microsoft Packaging API cannot write directly to Response.OutputStream.
// Therefore we use temporary MemoryStream.
using (MemoryStream documentStream = new MemoryStream())
{
    document.Save(documentStream, SaveOptions.DocxDefault);

    // Stream file to browser.
    Response.Clear();
    Response.ContentType = "application/vnd.openxmlformats";
    Response.AddHeader("Content-Disposition", "attachment; filename=Document.docx");

    documentStream.WriteTo(Response.OutputStream);

    Response.End();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...