2016-10-03 16 views
1

I have the app called osc and i want to create folder in root path and save image to that folder.wpf appのルートパスを見つけてイメージを保存するためのルートディレクトリにフォルダを作成するには?

は、私が "OSC /スクリーンショット/ EMPNAME/EMPID/scr.jpg" などのフォルダに画像を保存したい

助けてくれ

をフォルダを作成し、このパスに画像を保存する方法を

ありがとうございます

+0

は、[アプリケーションフォルダのパスを取得するための最良の方法]のhttp://stackoverflow.com/questions/938421/getting-the-applications-directory-from-a-wpf-application – Misters

+0

が重複する可能性を見てみましょう(http://stackoverflow.com/questions/6041332/best-way-to-get-application-folder-path) – rbr94

+0

私はそれを試みましたが、私はexeパスを取得しましたが、wpfアプリケーションのルートパスが必要です –

答えて

4

パスを表す文字列を取得するには:ルートフォルダに基づいて新しいパスを作成するには

DirectoryInfo directory = new DirectoryInfo(path); 

string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 

おそらくあなたは、次のような何かをしたい

var imagePath = path + @"\MyAppName\Images" 

if (!Directory.Exists(imagePath)) 
{ 
    DirectoryInfo di = Directory.CreateDirectory(imagePath); 
} 

編集:代替として、スペシャルフォルダを使用することができます。たとえば、LocalApplicationDataの場合、このフォルダー内でアプリケーションごとにマシンスコープのデータを配置できます。怒鳴るの例では、変数のlocalDataになります

C:\ Users \ユーザーUSER_NAME \のAppData \ローカル

USER_NAMEは、ユーザープロファイルをある

string localData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); 
    var imagePath = localData + @"\Images" 

if (!Directory.Exists(imagePath)) 
{ 
    DirectoryInfo di = Directory.CreateDirectory(imagePath); 
} 
+0

それは私のosc/bin/release/screenshots ....のような私のexeのパスを与えるが、私はルートディレクトリosc /にフォルダを作成したい。 –

+0

@SaurabhSolanki私は答えを –

+0

はい編集しましたが、bin/releaseフォルダのパスを返します。アプリケーションのルートパスが必要です –

1

AppDomain.CurrentDomain.BaseDirectoryあなたのアプリケーションフォルダへのパスを教えてくれます。

+2

として取ることはできません。それは私にosc/bin/release/screenshotsのような私のexeのパスを与えます....しかし、私はルートディレクトリosc /。 –

関連する問題