私のC#プログラムでは、ディレクトリを参照する必要があります。 私は方法 System.IO.Directory.GetFiles(directory)
を使用し、ディレクトリが "C:\ Program File"のような実際のディレクトリであるが、それが仮想ディレクトリ(librairieディレクトリなど)の場合、ディレクトリの値は次のようになります: ":: {031E4825 -7B94-4dc3-B131-E946B44C8DD5} \ Pictures.library-ms "と私はそれをブラウズする方法を知らない。C#でローカル仮想フォルダを参照するにはどうすればよいですか?
答えて
あなたは試す、物理一つに仮想パスを変換する必要があります。
DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath("your virtual folder here"));
あなたはDirectoryInfo上に読みたいかもしれません。
DirectoryInfo info = new DirectoryInfo("virtual folder here");
FileInfo[] files = info.GetFiles("*.*", SearchOption.AllDirectories);
私はこれがクレイジー古いですけど、場合には、誰かが解決策を望んでいる、ここで私はこれに探して過去半日かけて考え出したものです:それは使用です場合は、これに代わり、これを試してみます。そこにはあなたにthe folder names if you give it the path to the Virtual Folder's XML locationを得ることができるいくつかの解決策がありますが、私が見たことのないものは::{031E4825-....}
からそこに到着します。 WindowsAPICodePackのKnownFoldersBrowserの例を使用するにはhint in another question's answerがありました。だから私は、その中にソースコードを読み、次が出ている:
は、私は、フォルダを取得するために使用したダイアログボックスであり、私はライブラリフォルダの選択を可能にAllowNonFileSystemItems、それを有効にしている:
Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog dlg = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog();
dlg.Title = "Pick Folder";
dlg.IsFolderPicker = true;
dlg.InitialDirectory = Environment.SpecialFolder.Personal.ToString(); // If default setting does not exist, pick the Personal folder
dlg.AddToMostRecentlyUsedList = false;
dlg.AllowNonFileSystemItems = true;
dlg.DefaultDirectory = dlg.InitialDirectory;
dlg.EnsurePathExists = true;
dlg.EnsureFileExists = false;
dlg.EnsureReadOnly = false;
dlg.EnsureValidNames = true;
dlg.Multiselect = true;
dlg.ShowPlacesList = true;
if (dlg.ShowDialog() == Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult.Ok)
{
foreach (string dirname in dlg.FileNames)
{
var libFolders = ExpandFolderPath(dirname);
if (libFolders == null)
{
MessageBox.Show("Could not add '" + dirname + "', please try another.");
}
else
{
foreach (string libfolder in libFolders)
{
DoWork(libfolder);
}
}
}
}
allSpecialFolders
を反復処理して、これと同じ::{031E4825-...}
を見つけてください。これはSpecialFolderの構文解析名です(おそらくもっとエレガントな方法でしょう)。その後、そのライブラリフォルダ内のフォルダを取得するために他のソリューション(I used a CodeProject example that did the same thing)からの読み取りXMLを使用します。
/// <summary>Gets the folders associated with a path</summary>
/// <param name="libname"></param>
/// <returns>Folder, or List of folders in library, and null if there was an issue</string></returns>
public List<string> ExpandFolderPath(string foldername)
{
List<string> dirList = new List<string> { };
// If the foldername is an existing directory, just return that
if (System.IO.Directory.Exists(foldername))
{
dirList.Add(foldername);
return dirList;
}
// It's not a directory, so check if it's a GUID Library folder
ICollection<IKnownFolder> allSpecialFolders = Microsoft.WindowsAPICodePack.Shell.KnownFolders.All;
Regex libguid = new Regex(@"\b([A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-F0-9]{12})\b");
var match = libguid.Match(foldername);
if (match == null)
return null;
string fpath = "";
// Iterate over each folder and find the one we want
foreach (var folder in allSpecialFolders)
{
if (folder.ParsingName == foldername)
{
// We now have access to the xml path
fpath = folder.Path;
break;
}
}
if (fpath == "")
{
// Could not find it exactly, so find one with the same prefix, and
// replace the filename
foreach (var folder in allSpecialFolders)
{
if (folder.ParsingName.Contains(match.Groups[1].Value))
{
string sameDir = System.IO.Path.GetDirectoryName(folder.Path);
string newPath = System.IO.Path.Combine(sameDir, match.Groups[2].Value);
if (System.IO.File.Exists(newPath))
fpath = newPath;
break;
}
}
}
if (fpath == "")
return null;
var intFolders = GetLibraryInternalFolders(fpath);
return intFolders.Folders.ToList();
}
/// <summary>
/// Represents an instance of a Windows 7 Library
/// </summary>
public class Win7Library
{
public Win7Library()
{
}
public string Name { get; set; }
public string[] Folders { get; set; }
}
[DllImport("shell32.dll")]
static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out IntPtr pszPath);
//Handles call to SHGetKnownFolderPath
public static string getpathKnown(Guid rfid)
{
IntPtr pPath;
if (SHGetKnownFolderPath(rfid, 0, IntPtr.Zero, out pPath) == 0)
{
string s = System.Runtime.InteropServices.Marshal.PtrToStringUni(pPath);
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(pPath);
return s;
}
else return string.Empty;
}
private static string ResolveStandardKnownFolders(string knowID)
{
if (knowID.StartsWith("knownfolder:"))
{
return getpathKnown(new Guid(knowID.Substring(12)));
}
else
{
return knowID;
}
}
private static Win7Library GetLibraryInternalFolders(string libraryXmlPath)
{
Win7Library newLibrary = new Win7Library();
//The Name of a Library is just its file name without the extension
newLibrary.Name = System.IO.Path.GetFileNameWithoutExtension(libraryXmlPath);
List<string> folderpaths = new List<string>();
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); //* create an xml document object.
xmlDoc.Load(libraryXmlPath); //* load the library as an xml doc.
//Grab all the URL tags in the document,
//these point toward the folders contained in the library.
System.Xml.XmlNodeList directories = xmlDoc.GetElementsByTagName("url");
foreach (System.Xml.XmlNode x in directories)
{
//Special folders use windows7 Know folders GUIDs instead
//of full file paths, so we have to resolve them
folderpaths.Add(ResolveStandardKnownFolders(x.InnerText));
}
newLibrary.Folders = folderpaths.ToArray();
return newLibrary;
}
希望、これは将来的に誰かを助けます!
また、['Shell.Application.NameSpace(" :: {031E4825 -....} ").Items'](http://blogs.msdn.com/b/oldnewthing /archive/2013/02/04/10390725.aspx)。ライブラリのみを探している場合は、[ライブラリAPI](https://msdn.microsoft.com/en-us/library/windows/desktop/dd758094(v = vs.85).aspx)を使用できます。 – Mitch
- 1. Azure Resource Managerテンプレートで仮想アプリケーション/フォルダを作成するにはどうすればよいですか?
- 2. ネットワーク上のコンピュータから仮想マシン内のフォルダにアクセスするにはどうすればよいですか?
- 3. ユーザーがC#でファイルを参照できるようにするにはどうすればよいですか?
- 4. プログラムでページを参照するにはどうすればよいですか?
- 5. Angular2でコンポーネントを参照するにはどうすればよいですか?
- 6. PHPでクラスを参照するにはどうすればよいですか?
- 7. C#アプリケーションでCベースのDLLへの参照を追加するにはどうすればよいですか?
- 8. JavaScriptファイルを参照するにはどうすればよいですか?
- 9. オブジェクト参照を作成するにはどうすればよいですか?
- 10. クエリダイアログの参照に参照を挿入するにはどうすればよいですか?
- 11. C++/CLIで関数変数を参照によって渡すにはどうすればよいですか?
- 12. 同じソリューションでC++/CLiプロジェクトからC#プロジェクトを参照するにはどうすればいいですか?
- 13. C#WinformsアプリケーションでBindingSourceから参照を削除するにはどうすればよいですか?
- 14. クラスオブジェクトをC#でStringで参照するにはどうすればよいですか?
- 15. C#では、オブジェクトのプロパティを参照するにはどうすればよいですか?
- 16. C++/CLIでレポートコールバックの関数を参照渡しにするにはどうすればよいですか?
- 17. wpfでデータ仮想化をサポートするコンボボックスを作成するにはどうすればよいですか?
- 18. バニラ仮想ボックスホストとドッカーが同じ仮想ネットワークを使用するように設定するにはどうすればよいですか?
- 19. アセンブリ参照のソースコードへの参照を追加するにはどうすればよいですか?
- 20. C関数のポインタ引数にC++参照を渡すにはどうすればよいですか?
- 21. すべてのWPFアプリケーションで仮想キーボードを無効にするにはどうすればよいですか?
- 22. ビューでViewModelを参照するにはどうすればいいですか
- 23. ステンシルテーマでイメージを参照するにはどうすればいいですか
- 24. Xcodeでテキストフィールドを使用せずに仮想キーボードをポップアップするにはどうすればよいですか?
- 25. どのようにすれば、angularJSで仮想スクロールできますか?
- 26. Azureで特定の仮想マシンでアプリケーションサービスを作成するにはどうすればよいですか?
- 27. include_pathなしで仮想ホストでpropel ORMオブジェクトを生成するにはどうすればよいですか?
- 28. Bitcoin APIを仮想IPで21市場にホストするにはどうすればよいですか?
- 29. OpenFileDialogを使用せずにローカルディレクトリのファイルを参照するにはどうすればよいですか? (C#)
- 30. FTPは、私はCに常駐するフォルダの仮想フォルダに作成した仮想フォルダ
「Server.MapPath」とは何ですか?私はMapPathのために見つけることができたMSDNの参照はすべてSystem.Webの中にあります... OPはこれがWebアプリケーションであることを指定していませんでした。 – poncha
'OPはこれがウェブアプリケーションであると指定していませんでした。彼はそれがどちらでもないことを指定していませんでした... – dtsg
あなたは正しいです、彼はしませんでしたが、彼が与えた具体例は、疑いなくWebに関連しているシステムライブラリへの仮想パスでした... – poncha