Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

[C#] 特殊なフォルダパスを取得する

Posted at

やりたいこと

ProgramDataなどの特殊なフォルダに何かファイルを保存するとき、そのパスを直値でstringにいれてしまっていたが、そういう場合はそれ用のAPIを使ってやった方がいいらしい。

やり方

下記に、すべて書いてくれている。

特殊ディレクトリーを取得する
https://qiita.com/muro/items/fde18f72b28f4b46f07b

概要

Environment.GetFolderPathメソッドにEnvironment.SpecialFolderの列挙から欲しい項目を指定するとパスが取得できる。

string direcotryPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Console.WriteLine(directoryPath);

参照

特殊ディレクトリーを取得する
https://qiita.com/muro/items/fde18f72b28f4b46f07b

Environment.SpecialFolder Enum
https://docs.microsoft.com/ja-jp/dotnet/api/system.environment.specialfolder?redirectedfrom=MSDN&view=netframework-4.8

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?