0

I will be distributing my program. It will take pictures and save them to a folder. The problem is: C:/Users/G73/Desktop/

Everyone has there own file path... In the code it is

bitmap.Save("C:/Users/G73/Desktop/My OVMK Photos//OpenVMK" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg", ImageFormat.Jpeg);

It has my File path and the name of my computer... How would I make it to change to the users path?

Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
Devon Felix
  • 1
  • 1
  • 5

3 Answers3

2

Try this code:

string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
bitmap.Save(Path.Combine(path, "My OVMK Photos//OpenVMK", DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg"), ImageFormat.Jpeg);

It gets Desktop path for current user. You can get more special folders using Enviroment.SpecialFolder

Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
2

To get the user's desktop -

Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

Which you would use with a Path.Combine - e.g.:

bitmap.Save (Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "My OVMK Photos//OpenVMK...

Though for images you'd likely be better off using the My Pictures directory -

Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
NDJ
  • 5,189
  • 1
  • 18
  • 27
1

Try this

Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
Alessio
  • 2,018
  • 25
  • 26