It shows that you are unregistered. Please register with us by clicking Here
![]() |
|
![]() |
![]() | Register - FAQ - Today's Posts - New Posts - Support - Search | ![]() |
![]() |
![]() |
|
LinkBack | Thread Tools | Display Modes | ![]() |
|
|
#1 (permalink) |
|
Junior Member
Join Date: Jul 2006
Age: 42
Posts: 5
|
Export to Excel in ASP.NET is a very common feature, which I'm sure everyone who has worked in ASP.NET would have had the chance to implement.
Whenever we choose the Export to Excel option from our Application, a dialog box pops us with the option to Open or to Save. By chance if the user checks off the option "Always ask before opening this type of file" that is shown in the dialog box, from next time the user will not be able to see the dialog box. Instead, the excel file opens up in the same window. To set back this option, the following steps can be followed: 1. Go to Windows Explorer. 2. On the Tools menu, click Folder Options, and then click on the File Types tab. 3. From the Registered file types list box, select the XLS extension, and then click Advanced. 4. In the Edit File Type dialog box, set the Confirm open after download to selected. 5. Make sure the Browse in same window option is not selected, and then click OK. The above steps will make sure that we get the dialog box as shown above. However, since this is an option set at the client computer, these steps cannot be mandated to be followed in every computer that browses the application. So, from the code level, we must make sure that the excel file is opened in a separate window. One possible option for this is to Save the file to the web server, and then open the file in a separate window. The code for this is given below: private void ExportToExcel(DataGrid dgExport) { try { string strFileName = String.Empty, strFilePath= String.Empty; strFilePath = Server.MapPath(@"../Excel/") + "ExcelFileName" + ".xls"; if (File.Exists(strFilePath)) { File.Delete(strFilePath); } System.IO.StringWriter oStringWriter =new StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter); StreamWriter objStreamWriter; string strStyle =@" .text { mso-number-format:\@; } "; objStreamWriter = File.AppendText(strFilePath); dgExport.RenderControl(oHtmlTextWriter); objStreamWriter.WriteLine(strStyle); objStreamWriter.WriteLine(oStringWriter.ToString() ); objStreamWriter.Close(); string strScript = "<script language=JavaScript>window.open('../Excel/" + "ExcelFileName" + ".xls','dn','width=1,height=1,toolbar=no,top=300,l eft=400,right=1, scrollbars=no,locaton=1,resizable=1');</script>"; if(!Page.IsStartupScriptRegistered("clientScript") ) { Page.RegisterStartupScript("clientScript", strScript); } } catch(Exception) { //Handle Exception } } In the above method, the file is saved to the Web Server inside the folder "Excel". Of course, this folder must have write permissions for the user. But it will definitely ensure that the excel file is opened in a new window in the client computer. Cheers. Bradley |
|
|
|
|
|
|
|
#2 (permalink) |
|
Junior Member
Join Date: Feb 2009
Posts: 1
|
To me of 18 years. My guy act ons as the supervisor in close shop. To it already declared reduction of the rod, and that whom pleasure not degrade, -power discount the pay on 20 %. Certainly it on the one disposal is not a lot of, and with another it seems to me simply the commencement! And article has submit c be communicated across, there to be resulted the register of 10 not most demanded trades during critical time! I obviously too there is, and at you on profession something has exchanged after emergency? And how you in non-specialized procedure it to go through? Also what I can insist upon to advance my guy at least?
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| <span style="text-decoration: line-through; color: rgb(255, 0, 0);">These new emotico | m3talc0re | All Things General | 20 | 08-13-2006 01:51 AM |
| I’m a Totally newsier, forgive me for my "sty" quest | gabriel | Site and Server Administration | 0 | 07-29-2006 02:59 PM |
| open existing excel spreadsheet in browser | destiny | Perl | 1 | 07-21-2006 06:57 AM |
| "lets Make Love" Set V.1 | Archlord | Graphics & Multimedia | 21 | 10-14-2005 01:42 AM |