I have been using StreamWriters for a long and time and it has always worked but now I seem to be getting an Access Denied error while trying to save to the current users Desktop...

Dim savePath As String = "C:\Users\Josh\Desktop\EpiPhone\029.csv"
Using sw As New StreamWriter(savePath)
    '...Rest of code...
End Using

What are the most common problems with Access Denied while writing to the Desktop?

Re: Streamwriter Access Denied 80 80

The only thing that comes to mind is that you are not actually using the current user's name. Try using

Dim savePath As String = "%USERPROFILE%\Desktop\EpiPhone\029.csv"
Re: Streamwriter Access Denied 80 80

I am definately using my username because if I go in File Explorer, click on desktop and copy the address path it says the exact same as the savePath String. I'll still check to see if your code works though, thanks for the suggestion.

Re: Streamwriter Access Denied 80 80


I think you can get the current users desktop from the environment.specialfolders there is a .desktop (for the desktop virtual,) and a .desktopdirectory for the physical file directory.

commented: Right. I forgot about that. +12
Re: Streamwriter Access Denied 80 80

To find the desktop you could use the my namespace.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.