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) {
C#
this.GridView1.Page.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
hw.WriteLine(" Report");
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...

Posted Jun 16, 2011, 12:02 AM EDT
If is excel file,
FileInfo file = new FileInfo(FilePathName);
file.Attributes = FileAttributes.ReadOnly;
Hope this helps you.
Sweety45 reputationPosted Jun 16, 2011, 12:17 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Jun 17, 2011, 3:27 AM EDT