Results 1 to 8 of 8

Thread: Accepting files

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Accepting files

    Okay, how can I make it so I can open a file WITH my program? It's a simple editor, how do I make it accept files?

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You probably need to use some API and registering the ext of your files in the reg . Very easy way is to use InstallSheild . It has the option to add this functionality while installing your app . It does all the work for you .

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Pirate
    You probably need to use some API and registering the ext of your files in the reg . Very easy way is to use InstallSheild . It has the option to add this functionality while installing your app . It does all the work for you .
    I'm not even worried about registering my file, I want to know how my program can open a file if I select it and click open with...

  4. #4
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    you have to tell windows to pass the path to app and heres how you get it

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim strArgs() As String
    3.         Dim I As Integer
    4.         strArgs = Environment.GetCommandLineArgs()
    5.  
    6.         'strArgs(0) the path to the exe
    7.         'strArgs(1) is the first arg
    8.         'strArgs(2) is the second arg ect.
    9.        
    10.         For I = 0 To UBound(strArgs)
    11.             MsgBox(strArgs(I))
    12.         Next
    13.  
    14.     End Sub
    15. End Class
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  5. #5

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Thanks, I can get it so I can right click and open files right into my program, however if I run my program normally, I get an error.

    The 2nd arguement within the array is always the file's name and location, if I just run the program it will give me the location of my program's .exe. So as is, I can open other files into my program, I CANNOT just open the program by itself.

    I have an If statement on my main form which declares fileInfo so I can get the extension, and then I used an if statement to check, if it's an exe, then it just opens, otherwise it opens the file into the text box.
    VB Code:
    1. Dim fileInfo As New IO.FileInfo(strArgs(1))

    This works perfectly, except when the program is run normally, then it says this error:
    Code:
     Index was outside the bounds of the array.
    I'm confused, how can I make this work, I figured a simple if statemenet to check to see if the program is either being run or was given arguements.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You should encapsulate the handling of any arguments within an If..Then block to first see if there are any arguments. strArgs(1) assumes there are arguments passed in which when you run it normally there aren't.
    VB Code:
    1. Dim strArgs() As String
    2.         Dim I As Integer
    3.         strArgs = Environment.GetCommandLineArgs()
    4.  
    5.         If strArgs.Length>0 then
    6.  
    7.           'Handle arguments here
    8.           Dim fileInfo As New IO.FileInfo(strArgs(1))
    9.  
    10.  
    11.         End If

  7. #7

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    opps

  8. #8

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    nm thanks

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