English 中文(简体)
我如何确定Windows 下载链路?
原标题:How do I determine the Windows Download folder path?
  • 时间:2011-10-06 10:00:50
  •  标签:
  • c#
  • windows

On my machine, it s here:

string downloadsPath = Path.Combine(
   Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
   "Downloads");

但是,在一个同事机器上,这套手套确实存在,他的下载夹在我的文件夹中。 www.un.org/Depts/DGACM/index_french.htm

* Edit:事实上,它发现他不是用自己的机器操作,而是一台Windows 2003机器。

最佳回答
问题回答

您可使用 微软网络的Windows Code Pack。

参考:Microsoft.WindowsAPICodePack.Shell.dll

Need the following namespace:

using Microsoft.WindowsAPICodePack.Shell;

简单使用:

string downloadsPath = KnownFolders.Downloads.Path;

The VB. 我使用的净功能

<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 Result 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
        Result = Marshal.PtrToStringUni(ppszPath)
        Marshal.FreeCoTaskMem(ppszPath)
    End If
    
    as recommended by Ray (see comments below) 
    Marshal.FreeCoTaskMem(ppszPath)

    Return Result
End Function

在我的节目中,我呼吁它把一些CSV档案转移到另一个文件夹中。

    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




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签