none
How to get the current directory path c# winfows application

    Question

  •  

    Hi

       I created an application in c:\inetpub\wwwroot\windowsapplication. I want to save a file in folder "Image"

    I used Path.GetFullPath("Image") but it configures c:\inetpub\wwwroot\windowsapplication\bin\debug\image .It shows error cant find the folder.

    1. Tell me how to configure the folder in the windows application.

    2. I want to create a folder in the path where the windowsapplication.msi installs.

    Thanks

    Jhanani.R

    Monday, November 05, 2007 6:11 AM

Answers

  • To get the path that the Exe is running at  (which is a good location to add paths like "Image"), use:

     

    string exePath = Application.StartupPath + "\image";

     

    This path is the ..\bin\debug\image path when you run it on VS and ..\image path when you run it after installation.

    But you are talking about a path for a web-application, are you sure you want the windows application way...?

    Monday, November 05, 2007 11:40 AM
  •  

    From within your exe you can do this

     

    string image_outputDir = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

    DirectoryInfo df = new DirectoryInfo(outputDir + @"\images\");

     

    if(df.exists){

    // directory exists, do you want to delete it?

    // uncomment lines below to delete image directory if found

    // df.Delete(true);

     

    // uncomment line below to create new one

    //DirectoryInfo di = Directory.CreateDirectory(image_outputDir + @"\images\ );

     

    }

    else{

    // create new directory

    DirectoryInfo di = Directory.CreateDirectory(image_outputDir + @"\images\ );

    }

     

     

    this is from a winform application that creates an images directory if it doesn't already exist.

     

    If you want the installer to do it that depends on the installer application you are using?

    If innosetup for example

     

    under the [Dir] section type

    Name: {app}\images\

    under the [Files] section type

     

    Source: images\*.*; DestDir: {app}\images

    Again it depends on the tool you are using for the installer.

     

    Wednesday, August 20, 2008 5:32 PM

All replies

  • To get the path that the Exe is running at  (which is a good location to add paths like "Image"), use:

     

    string exePath = Application.StartupPath + "\image";

     

    This path is the ..\bin\debug\image path when you run it on VS and ..\image path when you run it after installation.

    But you are talking about a path for a web-application, are you sure you want the windows application way...?

    Monday, November 05, 2007 11:40 AM
  • In the solution explorer make sure the images in the image directory copy to output property is set to always copy or copy if newer.  This will make sure the image directory is created when you run the app

    Monday, November 05, 2007 11:42 AM
  • Hi
       Am sorry i cant get you.I dont want to create Image folder manully.It should be created by automatically.
    Thats is in the windows application before creating exe i want to check whether the folder is created by my coding and the images are uploaded in that folder.I want to create the folder in c:\windowsapplication\Images and not in c:\windowsapplication\bin\debug\.

    And whikle installing the msi the image folder should created in the path which is given by th user(that is the path where the msi installed)

    I tried to create folder using Directory.CreateDirectory.Before that i want to get the current path So i used Directory.GetCurrentDirectory(). It gives the path of the image which i selected to upload.

    Please solve my problems
    Thanks
    Jhanani.R
    Tuesday, November 06, 2007 5:01 AM
  •  

    From within your exe you can do this

     

    string image_outputDir = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

    DirectoryInfo df = new DirectoryInfo(outputDir + @"\images\");

     

    if(df.exists){

    // directory exists, do you want to delete it?

    // uncomment lines below to delete image directory if found

    // df.Delete(true);

     

    // uncomment line below to create new one

    //DirectoryInfo di = Directory.CreateDirectory(image_outputDir + @"\images\ );

     

    }

    else{

    // create new directory

    DirectoryInfo di = Directory.CreateDirectory(image_outputDir + @"\images\ );

    }

     

     

    this is from a winform application that creates an images directory if it doesn't already exist.

     

    If you want the installer to do it that depends on the installer application you are using?

    If innosetup for example

     

    under the [Dir] section type

    Name: {app}\images\

    under the [Files] section type

     

    Source: images\*.*; DestDir: {app}\images

    Again it depends on the tool you are using for the installer.

     

    Wednesday, August 20, 2008 5:32 PM
  • First two lines of code should be

     

    string image_outputDir = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

    DirectoryInfo df = new DirectoryInfo(image_outputDir + @"\images\");

     

     Daniel Leahy wrote:

     

    From within your exe you can do this

     

    string image_outputDir = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

    DirectoryInfo df = new DirectoryInfo(outputDir + @"\images\");

     

    if(df.exists){

    // directory exists, do you want to delete it?

    // uncomment lines below to delete image directory if found

    // df.Delete(true);

     

    // uncomment line below to create new one

    //DirectoryInfo di = Directory.CreateDirectory(image_outputDir + @"\images\ );

     

    }

    else{

    // create new directory

    DirectoryInfo di = Directory.CreateDirectory(image_outputDir + @"\images\ );

    }

     

     

    this is from a winform application that creates an images directory if it doesn't already exist.

     

    If you want the installer to do it that depends on the installer application you are using?

    If innosetup for example

     

    under the [Dir] section type

    Name: {app}\images\

    under the [Files] section type

     

    Source: images\*.*; DestDir: {app}\images

    Again it depends on the tool you are using for the installer.

     

    Thursday, August 21, 2008 3:22 PM
  • Is there a reason no one is escaping their backslashes?  e.g. ("\\images\\")  And is this the Daniel Leahy from Ygnacio Valley!?
    Friday, August 10, 2012 3:52 PM
  • You don't have to escape a backslash if the string has the 'string literal' character in from of it.  THe is what the '@' symbol is for.  If you omit the ampersand, you would then have to escape as you did above.

    Eric

    Friday, October 19, 2012 1:54 PM