In ASP.NET 4.0 using C#, how would you prevent READ-ONLY status when creating an Excel 2003 file by exporting records from GridView?

I'm writing my first ASP.NET 4.0 application using C# with VS2010.

I am trying to export a stored procedure result set to an Excel 2003 file.

When I create the new Excel file, I notice that the title bar states that it is READ-ONLY.

Do you know how I can modify my following code to get rid of the READ-ONLY status on the Excel file?

My code is in the attachment:
----------------------------
ExcelExport.txt
zimmer9Asked:
Who is Participating?
 
Chinmay PatelConnect With a Mentor Enterprise ArchitectCommented:
I don't think the solution provided by johny_bravo1 will work here. No offense johny_bravo1. This read only message is different than standard read only file scenario. Also this file being generated on server side this method will not have any impact.
0
 
Chinmay PatelEnterprise ArchitectCommented:
As this file is considered "downloaded" for security reasons it is marked as read only. Try adding this site to trusted sites section in your browser( still I think it might not work and make the file read only)
0
 
Johny BravoCommented:
Try this,

var fInfo = new FileInfo(YourFilePathName );
fInfo.IsReadOnly = false;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.