I am creating an C# win form application where user can specify any location to save a file. But, in default I need to provide the desktop path. But the desktop path changes depend on the Windows version, I found that:
 Environment.GetFolderPath(Environment.SpecialFolder.Desktop); 
can get the desktop path of any windows version. But the problem is how do I add this code to App.config file? Is there are special xml code block for this.
            Asked
            
        
        
            Active
            
        
            Viewed 1,207 times
        
    0
            
            
         
    
    
        Irshad
        
- 3,071
- 5
- 30
- 51
- 
                    1You might want to use the [Settings](http://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx) file instead – Jens Kloster Mar 11 '13 at 08:59
- 
                    I would suggest reading this [link](http://stackoverflow.com/questions/453161/best-practice-to-save-application-settings-in-a-windows-forms-application). should answer you question as well – Mr.GT Mar 11 '13 at 09:03
- 
                    I used the settings file. The link @MrGTgo gave me was the approach. – Irshad Mar 11 '13 at 09:06
2 Answers
0
            You have to add a settings-file to your project. There you need to create a property in the application-scope. This property you can access by
string path = Properties.Settings.Default.Path;
if(string.IsNullOrEmpty(path))
{
   path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
}
 
    
    
        Tomtom
        
- 9,087
- 7
- 52
- 95
0
            
            
        Go through AppDomain.GetData and AppDomain.SetData 
Have a constant like DESKTOP_DIRECTORY in you application & set its value to SpecialFolders.Desktop
You can then use AppDomain.GetData to retrieve it back.
You can then use it in your App.config file.
 
    
    
        Vignesh.N
        
- 2,618
- 2
- 25
- 33