dyarosh
asked on
Need to create a file in a folder in My Documents using c#
I am developing a Windows Application and I need to create a file in the following folder: My Documents\HWLocal77\Export s
Here is the code that I am using:
When my code tries to open the file I get the following error message:
Could not find a part of the path 'C:\Users\username\Documen ts\HWLocal 77\Exports \Census_52 015.txt'.
In tracing the error, C:\Users\username exists. Documents folder does not exist but My Documents folder does.
Can anyone tell me what I need to change so I can access the My Documents\HWLocal77\Export s folder regardless of which machine the application is installed on?
Here is the code that I am using:
string CensusFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\HWLocal77\Exports\Census_" + curDate.Month.ToString() + curDate.Year.ToString() + ".txt"
When my code tries to open the file I get the following error message:
Could not find a part of the path 'C:\Users\username\Documen
In tracing the error, C:\Users\username exists. Documents folder does not exist but My Documents folder does.
Can anyone tell me what I need to change so I can access the My Documents\HWLocal77\Export
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Using your suggestion I checked to see if the path exists and discovered one of my folders had a space in it that was missing in my string. The Documents folder mapped to the My Documents folder. Your suggestion helped lead me to the answer.
Open in new window