In my application i’m exporting gridview data to excel and storing it to a particular folder now what i want is to make this excel file as read only so that no one should edit it.
i have written code like this:
protected void Button5_Click(object sender, EventArgs e)
{
this.GridView1.Page.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
hw.WriteLine("<b><font size='5'> Report</font></b>");
this.GridView1.RenderControl(hw);
string HtmlInfo = tw.ToString();
string DocFileName = "Report" + ".xls";
string FilePathName = Request.PhysicalPath;
FilePathName = FilePathName.Substring(0, FilePathName.LastIndexOf("\\"));
FilePathName = @"C:\Excel" + "\\" + DocFileName;
FileStream Fs = new FileStream(FilePathName, FileMode.Create);
BinaryWriter BWriter = new BinaryWriter(Fs,System.Text.Encoding.GetEncoding("UTF-8"));
BWriter.Write(HtmlInfo);
BWriter.Close();
Fs.Close();
}
any1 help me on this…
You want to make the file readonly after it’s been written?
EDIT
This is for a website? I don’t know of a way you can prevent someone from downloading then modifying your file. You could use an API to do it instead. We use Aspose.Cells here to make Sheets readonly before sending them to the client.