You must Sign In to post a response.
  • Category: Visual Studio

    Saving a Text File in the path where VB application is running and installed

    Hi All....

    I am working in VB.NET Application and SQL Server 2005 . I want to save a text file either in a specified path or in the application directory where it is installed. On executing the application by using solution file it get created in debug folder but when publish the setup file and after i install the application the file is not getting created. Please give me a code for this

    Thanks and Regards
    Sankar
  • #767053
    Hi

    use following code to get path til bin/debug

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

    thanks

  • #767069
    it is very simple, just use Application.StartupPath property, it will give installed path
    see below code snippet

    string szPath = Application.StartupPath
    OR
    string szPath = AppDomain.CurrentDomain.BaseDirectory
    OR
    string szPath = My.Application.Info.DirectoryPath
    OR
    string szPath = IO.Path.GetFullPath(Application.ExecutablePath)
    OR
    string szPath =Path.GetDirectoryName(Application.ExecutablePath);

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767080
    Hi,
    Use this:
     
    string szAppInstalledDirectoryName = Application.ExecutablePath;
    szAppInstalledDirectoryName = szAppInstalledDirectoryName.Replace(szAppInstalledDirectoryName.Substring(szAppInstalledDirectoryName.LastIndexOf("\\")), "") + "\\";
    DirectoryInfo dir = new DirectoryInfo(szAppInstalledDirectoryName);
    FileInfo f = new FileInfo("D:\\abc.txt");
    f.MoveTo(dir.FullName);


  • Sign In to post your comments