Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I get an error message that the word file does not exist, below is the code so far.

this supposes to create a word document and replaces words in it, I think the problem is that I do not have access to the C:/temp folder, but i do not know what to replace it with? Tried C:/desktop still didnt work.

thanks
Posted
Updated 1-Sep-16 2:21am
v4
Comments
Richard MacCutchan 24-Aug-16 8:29am    
Replace it with the path to a directory that you do have access to.
Member 12699376 24-Aug-16 8:45am    
tried desktop still didnt work :(
Richard MacCutchan 24-Aug-16 8:49am    
Where is the file? Do you really have no way of checking where it is stored?
Richard Deeming 1-Sep-16 9:35am    
Removing the content of your question after it has been answered is extremely rude.

1 solution

C:\Desktop\ is not the path to the desktop folder, and C:\Temp\ is not the path to the temp folder. The real paths are within your user profile folder.

You can get the path to the temp folder with:
System.IO.Path.GetTempPath()

You can get the path to the desktop folder with:
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)


So, to save the file on your desktop, you would use:
string destinationFilePath = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
    "new.doc");


In either case, the first parameter to your CreateWordDocument function needs to be the real path of the existing file you want to open. If you specify a path that doesn't exist, you'll get your (misspelled) error message.
 
Share this answer
 
Comments
Richard MacCutchan 24-Aug-16 10:41am    
I just ran FileStream strIn = File.Open(@"C:\temp\foo.txt", FileMode.Open);, and it worked fine, opened the file no problem.
Richard Deeming 24-Aug-16 10:45am    
But that's not the standard location for the Temp folder.

If you create a folder called Temp in the root of C:, and give your account the necessary permissions, then it will work. But it won't exist by default.
Richard MacCutchan 24-Aug-16 11:02am    
Well my Windows 10 system has a Temp directory in the root of my C: drive. No idea how it got there, but I assume that Windows created it. And since that was the path that OP was using I (foolishly?) assumed that he/she had verified its existence via Explorer.
Richard Deeming 24-Aug-16 10:47am    
Temporary folder[^]:
In MS-DOS and Microsoft Windows, the temporary directory is set by the environment variable TEMP. Originally, the default was c:\Temp, then %WinDir%\Temp. In the Windows XP era, the temporary directory was set per-user as Local Settings\Temp, although still user-relocatable. For Windows Vista, 7 & 8 the temp location has moved again to within the AppData section of the User Profile, typically C:\Users\User Name\AppData\Local\Temp.
Richard MacCutchan 24-Aug-16 11:10am    
Interesting. I just checked my wife's system which has only ever had Windows 8 (very briefly), 8.1 and 10 installed, and it also has a C:\Temp directory. And I know that she would not have created it.

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