Click here to Skip to main content
15,921,203 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I Have done Export To Excel in VS 2005 using vb.net ,My code Works Fine on local machine but i put

the Same code on my Server its Not Working .

when i click on Excel to export button , target File gives me null values on server.

my Code where the exact error throughing is like below.



VB
Dim p As New Process
 p.StartInfo = New ProcessStartInfo(targetFilename)
 p.Start()



please Help its very important ..
Posted
Comments
Prasad Avunoori 3-Jun-14 0:35am    
Make sure you have read/write permission in IIS. Try Identity Impersonate=True in web.config.
DamithSL 3-Jun-14 0:49am    
is this ASP.net project? can you update the question with full code related to export to excel?
Maciej Los 3-Jun-14 1:57am    
Above sample code is totally irrelevant to the problem. Please, provide more details about issue.
Arvind Gaud 3-Jun-14 2:05am    
DataSet ds = CreateSampleData();

// Step 2: Create the Excel .xlsx file
try
{
string excelFilename = "C:\\Sample.xlsx";
CreateExcelFile.CreateExcelDocument(ds, excelFilename);
}


Dim p As New Process
p.StartInfo = New ProcessStartInfo(targetFilename)
p.Start()


this is updated code

You're attempting to open the Excel file on the server. When you run the site locally, that works, since the client and server are the same computer. When you deploy the site to a real server, it's not going to work. You need to send the Excel file to the client using Response.TransmitFile.

Also, based on your comment, you're trying to write the file to the root of the C: drive. Since your site won't be running as an administrative user, it won't have permission to write to that location. Pick a folder to which it does have access - for example, the App_Data folder within the site.

C#
DataSet ds = CreateSampleData();

// Build a path to which the application can write.
// Use a random file-name to avoid collisions from multiple simultaneous requests.
string targetFolder = Server.MapPath("~/App_Data/");
string excelFilename = Path.GetRandomFileName() + ".xlsx";
string excelPath = Path.Combine(targetFolder, excelFilename);

// Create the Excel file:
CreateExcelFile.CreateExcelDocument(ds, excelPath);

// Transmit the file to the client:
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", "attachment;filename=Sample.xlsx");
Response.TransmitFile(excelPath);
Response.Flush();

// Delete the temporary file:
File.Delete(excelPath);
 
Share this answer
 
 
Share this answer
 
Comments
Arvind Gaud 3-Jun-14 1:40am    
thanks For your reply rajeesh.

i referred above Code and implemented but this doesnot Worked out my problems please suggest something else.
Hi,

I have encountered these kind of situation in my past.

The common problem is in the server there is no office/excel installed.

Please try to download and install the below access engine.

http://www.microsoft.com/en-in/download/details.aspx?id=13255

You didn't mentioned which version of excel you have. Please try to download and install appropriate version in the server machine.

Hope this helps!

- S Francis
My Blog
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900