Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application i am dynamically creating an excel to show its preview.When preview button is clicked a copy of excel file is dynamically created in bin\debug folder of my application it is opened to show preview. It works fine in the application , but wen the application is run using its build excel file not creating in application folder. I gave complete premission for application folder bt still problem exist.

Plz.. help me..
Posted
Comments
PSK_ 15-Jun-10 1:11am    
Are you getting any exception? Have you checked the event logs?
Sandeep Mewara 15-Jun-10 2:23am    
You need to provide more info on what's happening in case of issue. Error logs, event viewer, etc...

You should be creating data files in the appropriate application data folder, not the application's folder.

You can use this to get the name of the folder:

Environment.GetFolderPath(SpecialFolder.xxxxx) 


where "xxxxx" is one of the following:

ApplicationData<br />
CommonApplicationData<br />
LocalAplicationData


Go here to determine which of those you want to use:

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx[^]

The reason you use this method is because different versions of Windows use different names for these "special" folders.
 
Share this answer
 
hi friend,

Try this code

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();
    }
    catch(Exception)
    {}
}



this is just reference,

Accept this answer if this will usefull to you.

Thanks,
Mahesh patel
 
Share this answer
 
Comments
Henry Minute 18-Jun-10 8:56am    
Read the question properly. The OP stated that his code worked correctly. They do not need code to create an Excel file, they need reasons that it won't do so on another system.
John is right. On newer OSes, it's not possible to give 'full permission' to the app folder. Perhaps it would also help if you told us what happens when you try to create this file, but it doesn't matter. Do it in the right place and it will work.
 
Share this answer
 

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