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 8055181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:18:50+00:00 2026-06-05T08:18:50+00:00

I am creating a excel report and html report in asp.net when I clik

  • 0

I am creating a excel report and html report in asp.net when I clik the button and my application create it and save to the client desktop but, it is not working correctly because excel file is creating in server’s desktop. How can I fix this matter ?

Thank you for your reply.

string CurrentDate;
DateTime saveNow = DateTime.Now;
CurrentDate = saveNow.Date.ToShortDateString();
string reportContent = prepareHTM();

string pathFile = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory) + "\\As_Build_Report_ "+ CurrentDate + ".html";

using (StreamWriter outfile = new StreamWriter(pathFile, true))
{
    outfile.WriteLine(reportContent);
}
System.Diagnostics.Process.Start(pathFile);

object missing = System.Reflection.Missing.Value;
//Start Excel Application.
Excel.Application oXL = new Excel.Application();
oXL.Visible = true; //display Application .            
Excel._Workbook oWB = (Excel._Workbook)(oXL.Workbooks.Add(missing));//create a new workbook.
Excel._Worksheet oSheet = (Excel._Worksheet)oWB.ActiveSheet; //create a sheet                

string CurrentDate;
DateTime saveNow = DateTime.Now;
CurrentDate = saveNow.Date.ToString();
int keep = 5;
string project = list[0].Project;
oSheet.Cells[1, 3] = "MiKES Configuration Management __" + project + "__ As-Built Report";
oSheet.Cells[3, 1] = "Report Date :";
oSheet.Cells[3, 2] = CurrentDate;

oSheet.Cells[keep, 1] = "PART NO";
oSheet.Cells[keep, 2] = "REF.DES.";
oSheet.Cells[keep, 3] = "DESCRIPTION";
oSheet.Cells[keep, 4] = "SERIAL NO";
oSheet.Cells[keep, 5] = "C/S";
oSheet.Cells[keep, 6] = "D/C";
oSheet.Cells[keep, 7] = "REMARK";
keep++;
foreach(Classes.CMNewPart item in list)
{
    try
    {
        oSheet.Cells[keep, 1] = item.PartNo;
        oSheet.Cells[keep, 2] = item.RefDes;
        oSheet.Cells[keep, 3] = item.Description1;
        oSheet.Cells[keep, 4] = item.SerialNo;
        oSheet.Cells[keep, 5] = item.Cs;
        oSheet.Cells[keep, 6] = item.Dc;
        oSheet.Cells[keep, 7] = item.Remark;
    }
    catch (Exception)
    {

    }
    keep++;
}
  • 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-06-05T08:18:52+00:00Added an answer on June 5, 2026 at 8:18 am

    You need to send the file to client using Response object. To ignore the warning message like when client is opening the excel file –

    enter image description here

    To prevent this you need to mention the content type and length in the response
    use the sample code

    //Read the Excel file in a byte array. here pck is the Excelworkbook              
    Byte[] fileBytes = pck.GetAsByteArray();
    
    //Clear the response               
    Response.Clear();
    Response.ClearContent();
    Response.ClearHeaders();
    Response.Cookies.Clear();
    //Add the header & other information      
    Response.Cache.SetCacheability(HttpCacheability.Private);
    Response.CacheControl = "private";
    Response.Charset = System.Text.UTF8Encoding.UTF8.WebName;
    Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
    Response.AppendHeader("Content-Length", fileBytes.Length.ToString());
    Response.AppendHeader("Pragma", "cache");
    Response.AppendHeader("Expires", "60");
    Response.AppendHeader("Content-Disposition",
    "attachment; " +
    "filename=\"ExcelReport.xlsx\"; " +
    "size=" + fileBytes.Length.ToString() + "; " +
    "creation-date=" + DateTime.Now.ToString("R") + "; " +
    "modification-date=" + DateTime.Now.ToString("R") + "; " +
    "read-date=" + DateTime.Now.ToString("R"));
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    //Write it back to the client    
    Response.BinaryWrite(fileBytes);
    Response.End();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a report in my ASP.NET application. The report outputs to Excel
I am creating an excel report from vb.net. Now it works. But i realize
I am creating a pivot table excel sheet in my ASP .NET web application
I am creating an excel report in vb.net using the office interop. When the
I am creating a Generate Report button for some data in my application. The
I'm creating HTML (popup window), EXCEL and PDF report and would like to show
I am creating Excel using DocumentFormat.OpenXml in ASP.Net. Can anybody have idea how can
I'm creating an Excel file in C# on my asp.net web site. Then, I
I am creating an instance of Microsoft Excel in a .NET application (WPF if
I am creating a C# windows application to create an Excel 2003 sheet. There

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.