The VB.Net (not C#) function that I use is following
<DllImport("shell32.dll")>
Private Function SHGetKnownFolderPath _
(<MarshalAs(UnmanagedType.LPStruct)> ByVal rfid As Guid _
, ByVal dwFlags As UInt32 _
, ByVal hToken As IntPtr _
, ByRef pszPath As IntPtr
) As Int32
End Function
Public Function GetDownloadsFolder() As String
Dim sResult As String = ""
Dim ppszPath As IntPtr
Dim gGuid As Guid = New Guid("{374DE290-123F-4565-9164-39C4925E467B}")
If SHGetKnownFolderPath(gGuid, 0, 0, ppszPath) = 0 Then
sResult = Marshal.PtrToStringUni(ppszPath)
Marshal.FreeCoTaskMem(ppszPath)
End If
Return sResult
End Function
In my program, I call it to move some CSV files in another folder using following code.
Dim sDownloadFolder = GetDownloadsFolder()
Dim di = New DirectoryInfo(sDownloadFolder)
'Move all CSV files that begin with BE in specific folder
'that has been defined in a CONFIG file (variable: sExtractPath
For Each fi As FileInfo In di.GetFiles("BE*.csv")
Dim sFilename = sExtractPath & "\" & fi.Name
File.Move(fi.FullName, sFilename)
Next