Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using selenium application to download an excel file from web. The file is downloaded in read only format, that is it doesn't gets saved after downloading. But once it downloads before opening the excel throws a security warning in which it has 2 buttons-enable and disable. Since I am coding in c#, I want c# to handle that window.

That is I want c# to click on "Enable" button of that excel sheet. Is it possible?? Any comments would be really appreciated..

thanks.
Posted
Updated 16-Jul-13 23:54pm
v2
Comments
Dheeraj_Gupta 17-Jul-13 6:09am    
your question is not pretty clear... could you please share some screen shots for the same.
Maciej Los 17-Jul-13 12:50pm    
Agree ;)

1 solution

Hi,
From where you are downloading the Excel file.
if my guess is for example from gridview your exporting data to excel then try like this.

C#
this.GridView1.Page.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        hw.WriteLine("<font size="3"> Test</font>");
        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;
          var fileInfo = new FileInfo(FilePathName );
           fileInfo.IsReadOnly = false;
        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();
 
Share this answer
 
v2

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