Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem in receiving Path as a string

Problem in receiving Path as a string

Scheduled Pinned Locked Moved C#
csharphelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    selcuks
    wrote on last edited by
    #1

    Hello, First of all thank you for this magnificent web site. I am new to C# and trying some basics on my own. As you may know if you try to define a path variable as a string in C# you must use "\\" to indicate backslashes: i.e.: string filePath = "C:\\Windows\\Temp\\file.txt"; But what if I should received the path information as a parameter to my main() method? I have tested it many times in simple applications but I could not open a SaveFileDialog in the specified directory. Please consider the following examples that sets SaveFileDialog.InitialDirectory property. The operation of the application is simple, just display a SaveFileDialog pointing to the location passed to the Form1: This one works pretty fine: /// /// The main entry point for the application. /// [STAThread] static void Main() { string initialDirectory = "C:\\Windows\\Temp"; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(initialDirectory )); } and Form1 class has the following codes inside: public partial class Form1 : Form { private string initialDirectory; public Form1(string initialDirectory) { this.initialDirectory = initialDirectory; InitializeComponent(); InitializeSvFDlg(); } private void InitializeSvFDlg() { this.saveFileDialog1.InitialDirectory = this.initialDirectory; this.saveFileDialog1.ShowDialog(); } } -------------------------------------------------------------- I observed that SaveFileDialog does not show the passed directory when I use the following method in main() and start the program from Command Prompt with SvFileDlgShow.exe "C:\\Windows\\Temp" command: /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { string initialDirectory = args[0]; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(initialDirectory)); } Form1 class is the same. -------------------------------------------- But the executable works fine if I use SvFileDlgShow.exe "C:\Windows\Temp" as the start-up command. Is this the i

    C 1 Reply Last reply
    0
    • S selcuks

      Hello, First of all thank you for this magnificent web site. I am new to C# and trying some basics on my own. As you may know if you try to define a path variable as a string in C# you must use "\\" to indicate backslashes: i.e.: string filePath = "C:\\Windows\\Temp\\file.txt"; But what if I should received the path information as a parameter to my main() method? I have tested it many times in simple applications but I could not open a SaveFileDialog in the specified directory. Please consider the following examples that sets SaveFileDialog.InitialDirectory property. The operation of the application is simple, just display a SaveFileDialog pointing to the location passed to the Form1: This one works pretty fine: /// /// The main entry point for the application. /// [STAThread] static void Main() { string initialDirectory = "C:\\Windows\\Temp"; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(initialDirectory )); } and Form1 class has the following codes inside: public partial class Form1 : Form { private string initialDirectory; public Form1(string initialDirectory) { this.initialDirectory = initialDirectory; InitializeComponent(); InitializeSvFDlg(); } private void InitializeSvFDlg() { this.saveFileDialog1.InitialDirectory = this.initialDirectory; this.saveFileDialog1.ShowDialog(); } } -------------------------------------------------------------- I observed that SaveFileDialog does not show the passed directory when I use the following method in main() and start the program from Command Prompt with SvFileDlgShow.exe "C:\\Windows\\Temp" command: /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { string initialDirectory = args[0]; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(initialDirectory)); } Form1 class is the same. -------------------------------------------- But the executable works fine if I use SvFileDlgShow.exe "C:\Windows\Temp" as the start-up command. Is this the i

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      selcuks wrote:

      But what if I should received the path information as a parameter to my main() method?

      The reason you use \\ is because \ is used to escape characters, for example, \" is how you put a quote. You have another option: @"c:\Program Files\Atalasoft\DotImage 6.0" will work fine, the @ means that \ means \. The \\ actually is turned into \ in your final string ( although the debugger will show \\ ). So, if you pass a parameter, it should be a single \, because \\ is in fact how you tell the compiler to emit a single \, if you've not put @ at the front of the string.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups