locked
Illegal characters in path RRS feed

  • Question

  • I keep getting an error, illegal characters in path when there isn't..


            Dim sfd As New FolderBrowserDialog
            If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
                For Each Item As ListViewItem In ListView.Items
                    Dim ExtractionPath As String = sfd.SelectedPath
                    If ExtractionPath.Substring(ExtractionPath.Length - 1, 1) = "\" Then
                        ExtractionPath = ExtractionPath.Substring(0, ExtractionPath.Length - 1)
                    End If
                    ExtractFile(FilePath, ExtractionPath & "\" & Item.SubItems(0).Text , Replace(Item.SubItems(4).Text, "0x", "&H"), Item.SubItems(6).Text, Item.SubItems(2).Text)
                Next
    End If



    Path I'm combining = ExtractionPath & "\" & Item.SubItems(0).Text

    I would wrap the code but its f**king it up.


    I have a break and it's giving errors on paths like:

    C:\FFFE07D1.gpd
    C:\Documents and Settings\NaTe.NATE-104AD939AF\Desktop\spa.bin
    E:\default.wmv

    Any path I give it, it always returns an error when it shouldn't



    I'm using the paths like:


    Dim writer As New BinaryWriter(New FileStream(filename, FileMode.Create, FileAccess.Write))


    filename being the path that's passed on
    Monday, October 5, 2009 11:08 PM

Answers

  • Hi again,

    you have a vbNullChar at the end of your filename. Remove it and it will work.
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Marked as answer by NaTeXBL Friday, October 9, 2009 9:46 PM
    Friday, October 9, 2009 10:12 AM

All replies

  • Try using the System.IO.Path.Combine() method to clean up your path strings.  That method will either return a valid path, or Nothing.
    Mark the best replies as answers. "Fooling computers since 1971."
    Monday, October 5, 2009 11:35 PM
  • Still getting the error:

                    Dim FileName As String = Item.SubItems(0).Text
                    Dim ExtractionPath As String = Path.Combine(sfd.SelectedPath, FileName)



    'FileName = default.wmv
    'sfd.SelectedPath = C:\
    Monday, October 5, 2009 11:47 PM
  • I don't know what to say.

    "C:\"  

    That is a valid path.  Perhaps the strings are not what you think they are.
    Mark the best replies as answers. "Fooling computers since 1971."
    Monday, October 5, 2009 11:53 PM
  • I don't know what to say either... I know for a fact the path is correct but microsoft seems to think different.

    Like I said I've set a breakpoint and I'm looking at the values but it still insists there's illegal characters. I've been programming with VB for a couple years and this has ALWAYS been a problem. I'm using 05 but I've also tried 08 and it gives the same result.
    Monday, October 5, 2009 11:58 PM
  • Are there the correct number of "" "" to make the program search for the string of the path? I've had to use as many as 3 " on either side in the past to make the compiler look for a string.
    If you're not living on the edge, you're taking up too much room
    Tuesday, October 6, 2009 8:05 AM
  • Hi,

    you should show us the code for the ExtractFile Method. I guess you get the exception from this method.
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Tuesday, October 6, 2009 8:18 AM
  • Hi NaTeXBL,

    Would you please  show us the ExtractFile Method? I think Heslacher is right

    Regards
    Jeff Shan
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, October 9, 2009 8:21 AM
  •     Public Sub ExtractFile(ByVal localfile As String, ByVal filename As String, ByVal offset As Long, ByVal size As Integer, ByVal blockcount As Integer)
            ProgressBar1.Maximum = 100
            ProgressBar1.Value = 0
            Dim ChunkEnd As Integer = (blockcount * &H1000) Mod size
            Dim reader As New BinaryReader(New FileStream(localfile, FileMode.Open, FileAccess.Read))
            Dim writer As New BinaryWriter(New FileStream(filename, FileMode.Create, FileAccess.Write))
            Dim cluster As Long = Convert.ToInt64(blockcount)
            Dim num3 As Long = Convert.ToInt64(size)
            Dim num4 As Long = (num3 >> 12)
            Dim num5 As Long = (num3 - (num4 << 12))
            Dim i As Long = cluster
            Do While (i < (cluster + num4))
                reader.BaseStream.Position = (i * &H1000) + &HC000
                writer.Write(reader.ReadBytes(&H1000))
                Dim str As String = String.Format("{0}%", ((100 * (i - cluster)) / num4))
                If str <> Label5.Text Then
                    Label5.Text = str
                    ProgressBar1.Value = CInt(Replace(str, "%", ""))
                    Application.DoEvents()
                End If
                i += 1
            Loop
            reader.BaseStream.Position = (offset + (cluster + num4))
            writer.Write(reader.ReadBytes(CInt(num5)))
            reader.Close()
            writer.Close()
        End Sub
    Friday, October 9, 2009 8:29 AM
  • Thanks for showing the code.

    Another thing what i would need to know:

    ExtractFile(FilePath, ..,..

    what is the FilePath Variable containing. Is it a path ( folder name ) or is it path and filename ?


    PS: I guess you should really set OPTION Strict ON

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Friday, October 9, 2009 8:45 AM
  • filename being the new file path passed on, it's a path and file name (see first post)
    Friday, October 9, 2009 8:52 AM
  • ok,

    so if you set a breakpoint to first line of the ExtractFile method, and single step through the code, where is the exception been thrown ?


    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Friday, October 9, 2009 8:56 AM
  • I marked the problem in bold, when creating a new filestream. There shouldn't be a problem.. that's what I've been saying, there's nothing wrong with the path, vb just doesn't want to do it.
    Friday, October 9, 2009 9:34 AM
  • If i execute the following code it is working like a charme. Does this workt with your system ?

            Dim oFd As New FolderBrowserDialog
            oFd.ShowDialog()
            Dim filename As String = Path.Combine(oFd.SelectedPath, "default.wmv")
            Dim writer As New BinaryWriter(New FileStream(filename, FileMode.Create, FileAccess.Write))

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Friday, October 9, 2009 9:44 AM
  • http://img195.imageshack.us/img195/7362/dghgh.png
    Friday, October 9, 2009 9:58 AM
  • Hi again,

    you have a vbNullChar at the end of your filename. Remove it and it will work.
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Marked as answer by NaTeXBL Friday, October 9, 2009 9:46 PM
    Friday, October 9, 2009 10:12 AM
  • I marked the problem in bold, when creating a new filestream. There shouldn't be a problem.. that's what I've been saying, there's nothing wrong with the path, vb just doesn't want to do it.


    Why didn't you just simply post that code from the start? 
    Ya know, the code that actually throws the error.

    I posted to point out that you are not first calling Flush on your Writer object before you call Close. 
    Flush will ensure that all data gets written.  Simply calling Close can result in truncated files.



    Mark the best replies as answers. "Fooling computers since 1971."
    Friday, October 9, 2009 12:49 PM
  • Hi again,

    you have a vbNullChar at the end of your filename. Remove it and it will work.
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/



    Thank you VERY much!
    Friday, October 9, 2009 9:47 PM