Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6679757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:23:44+00:00 2026-05-26T04:23:44+00:00

I use Sharepoint 2010 and I am developing a web part where on a

  • 0

I use Sharepoint 2010 and I am developing a web part where on a button click event, a pdf file needs to be generated and opened directly. Should not be saving onto the disk.
I tried the below code

 protected void Button1_OnClick(object sender, EventArgs e)
    {
        Document myDoc = new Document(PageSize.A4.Rotate());
        try
        {
            PdfWriter.GetInstance(myDoc, new FileStream(@"C:\Directory\Test.pdf", FileMode.Create));
            myDoc.Open();
            myDoc.Add(new Paragraph("Hello World"));
        }
        catch (DocumentException ex)
        {
            Console.Error.WriteLine(ex.Message);
        }
        myDoc.Close();
    }

I also tried the below code which also generates the file on the Server which I dont want.

  Document document = new Document(PageSize.A4);
        PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.Server.MapPath("~/Test.pdf"), FileMode.Create));
        document.Open();
        var WelcomePara = new Paragraph("Hello World");
        document.Add(WelcomePara);
        document.Close();

This one creates the pdf file on the desktop, I need it to be opened in the pdf format.Can someone help me please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:23:45+00:00Added an answer on May 26, 2026 at 4:23 am

    I was able to get it work finally.

      using (var ms = new MemoryStream())
          {
              using (var document = new Document(PageSize.A4,50,50,15,15))
              {
                  PdfWriter.GetInstance(document, ms); 
                  document.Open();
                  document.Add(new Paragraph("HelloWorld"));
                  document.Close();
              }
              Response.Clear();
              //Response.ContentType = "application/pdf";
              Response.ContentType = "application/octet-stream";
              Response.AddHeader("content-disposition", "attachment;filename= Test.pdf");
              Response.Buffer = true; 
              Response.Clear();
              var bytes = ms.ToArray();
              Response.OutputStream.Write(bytes, 0, bytes.Length);
              Response.OutputStream.Flush();
          } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you use user controls to include file code in sharepoint 2010 web parts?
I have been developing pages and web parts in SharePoint 2007/2010 for the past
I have a Sharepoint 2010 site with a Silverlight web part. When someone comes
Background: I have a built-in-house custom SharePoint 2010 web part, inheriting from System.Web.UI.WebControls.WebParts.WebPart ,
I'm using Javascript inside of a SharePoint 2010 Content Editor Web Part to insert
The Sharepoint 2010 Current User Filter Web Part allows List Web Parts that have
I have a SharePoint 2010 web application that I'd like to use a custom
I'm developing a SharePoint 2010 solution which consists of some web parts and other
I am planning to use my laptop for SharePoint 2010 development and I have
How can I create and use a SharePoint 2010 project that references a .Net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.