-1

VERY VERY new to C Sharp, as it's not part of my study path, but I have to edit small codes in C Sharp in order for my app to work. I'm using Ogama, a open source gaze tracker, which I need for my project. The heatmap, to be more specific. Now, I want to save the heatmap to a directed folder, and managed to find the code. The initial code was

 public static bool ExportImageToFile(Image image)
{
  SaveFileDialog dlg = new SaveFileDialog();
  dlg.Title = "Please enter filename for image...";
  dlg.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();

So I thought I could change it, by following other tutorials online, and this was my code.

public static bool ExportImageToFile(Image image)
{
  SaveFileDialog dlg = new SaveFileDialog();
  dlg.Title = "Please enter filename for image...";
dlg.InitialDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "heatmapimages");

But it doesn't work. When I click the save file button, it brings me to where my Ogama projects are. The 'heatmapimages' folder is in my Desktop. Any advice? Thank you in advance. EDIT: Managed to make it work, by changing Special.Personal to Special.DesktopDirectory. Is there a way to make it autosave the image? Such that I don't need to click save?

CharithJ
  • 46,289
  • 20
  • 116
  • 131
  • It looks like you want [`SpecialFolder.Desktop`](http://stackoverflow.com/a/634145/21475) instead of `Personal`? – Cameron Jul 21 '15 at 03:04
  • @Cameron, yeap! Decided to try and change to Desktop.Directory, and it worked! Is there anyway that it will auto save the image? And such that I don't need to click save? – Exclusified Jul 21 '15 at 03:07
  • 1
    Your autosave question would be better served if you asked a new question; we try to keep each question focused on just a single topic at a time. – Michael Edenfield Jul 21 '15 at 03:11
  • @Exclusified: See here on how to save an image. http://stackoverflow.com/questions/2290644/save-image-files-in-c-sharp – CharithJ Jul 21 '15 at 03:20
  • @MichaelEdenfield, noted! Thank you! – Exclusified Jul 21 '15 at 06:42

1 Answers1

0

You need to set RestoreDirectory true and set InitialDirectory to SpecialFolder.Desktop. Here are all SpecialFolders for your reference.

It restores the current directory to its original value if the user changed the directory while searching for files.

CharithJ
  • 46,289
  • 20
  • 116
  • 131