Results 1 to 6 of 6

Thread: [3.0/LINQ] Opening Files?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2007
    Posts
    34

    [3.0/LINQ] Opening Files?

    I never realized this would be such a hassle, and oddly enough, none of my books really helped me out on the matter.

    What I did in VB was simply this

    Code:
    System.Diagnostics.Process.Start("\directory\file.bat")
    And it worked.

    I've been googling and flipping through pages, but have no idea on how to reproduce this in C#.

    Can I please get some help?

    Thanks in advance,
    Eleven

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [3.0/LINQ] Opening Files?

    You'd do it the same way.
    Altough, you will have to put an @ in front of the string path (or use double slashes //), or else itll recognize the slashes as escape sequences.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2007
    Posts
    34

    Re: [3.0/LINQ] Opening Files?

    odd, I tried that and it couldn't find the files.

    The program is located in a root folder, and I am looking for a file in a subdirectory down. Here is what it looks like so far:

    Code:
    System.Diagnostics.Process.Start("@[email protected]");
    File is located just before directory, it's here:

    Code:
    C:\...\File\Directory\File.bat
    File.bat is what I'm trying to open. But I get an error saying it cannot find the file specified.
    Last edited by Eleven; Feb 2nd, 2008 at 05:25 PM.

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [3.0/LINQ] Opening Files?

    oh, sorry for the confusion, what i ment was that you should place the @ infront of the entire string, like this:
    System.Diagnostics.Process.Start(@"directory/file.bat")
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2007
    Posts
    34

    Re: [3.0/LINQ] Opening Files?

    Ah okay, my fault then, thanks a lot for your help!

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [3.0/LINQ] Opening Files?

    To clarify: Strings in C# can contain escape sequences. An example of an escape sequence is \n, which produces a newline character. VB doesn't support these, so backslash characters have no meaning in VB string literals.

    To write a backslash in a C# string literal, you can either use the backslash escape sequence \\, or turn it into a verbatim string literal by prepending the @ character, as Atheist showed you. This disables all escape sequences in the literal (except for \", which is necessary for embedding double quote characters).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width