简体   繁体   中英

save file to my documents

I want to create a program that saves a bmp picture to my documents and uses that picture as wallpaper. So far I managed to create the program and it runes pretty nice. But one problem, I dont know how to save the bmp file to my documents (every computer has a different path). Please help me find out a way to find the path to my documents.

System.Drawing.Image img = Properties.Resources.pic;
img.Save("D:\\wall.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
key.SetValue(@"Wallpaper", "D:\\wall.bmp");
RegistryKey key2 = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
key2.SetValue(@"WallpaperStyle", 2.ToString());
key2.SetValue(@"TileWallpaper", 0.ToString());
SystemParametersInfo(
           SPI_SETDESKWALLPAPER, 
           0, 
           "D:\\wall.bmp", 
           SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);

尝试

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

I suspect you want the Environment.SpecialFolder enumeration:

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

and combine it with Environment.GetFolderPath :

http://msdn.microsoft.com/en-us/library/system.environment.getfolderpath.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM