locked
Using a # in a filename RRS feed

  • Question

  • I often use things like the crosshatch in filenames to group them together.  Until recently this has not been a problem.

    I am working modifing a WPF app which uses a Listbox to store images.  I need the full path of the image to feed to a class to retrieve metadata.

    The test image is named "# Canon-ixus.jpg".

    Using Listbox.SelectedValue to return the filename I get "%23 Canon-ixus.jpg".  There are not a whole lot of options to returning the name of the selected item from the Listbox.

    Is there any simple way to get the name back to its original form???

    Saturday, August 14, 2010 3:25 PM

Answers

  • You'll also need to right-click your solution name in the solution explorer, choose "Add Reference...", and under the ".NET" tab find System.Web.

    Then, in your code, decode the string with HttpUtility.UrlDecode.

    HTH,

    Andrew

    • Marked as answer by TaubertRC Saturday, August 14, 2010 7:45 PM
    Saturday, August 14, 2010 5:33 PM
  • Which version of VS are you using?

    You could try adding the reference again, to tell it you /really/ want to use it :)

    Or use System.Uri.UnescapeDataString, which I just found

    --
    Andrew

    • Marked as answer by TaubertRC Saturday, August 14, 2010 7:45 PM
    Saturday, August 14, 2010 7:34 PM

All replies

  • It looks like you are getting back an HTML encoded string.  There is a HTMLDecode function and you can find information here:

    http://msdn.microsoft.com/en-us/library/hwzhtkke.aspx


    www.sqlquerybuilder.com
    If I answered your question please mark my post as the answer.
    Saturday, August 14, 2010 3:55 PM
  • Thank you for your reply but I can't get that command to work.  I imported System.web but it still shows invalid.

    Saturday, August 14, 2010 5:12 PM
  • You'll also need to right-click your solution name in the solution explorer, choose "Add Reference...", and under the ".NET" tab find System.Web.

    Then, in your code, decode the string with HttpUtility.UrlDecode.

    HTH,

    Andrew

    • Marked as answer by TaubertRC Saturday, August 14, 2010 7:45 PM
    Saturday, August 14, 2010 5:33 PM
  • Yes, I did that as well.  Even tried prefacing it with System.Web.
    Saturday, August 14, 2010 7:23 PM
  • Which version of VS are you using?

    You could try adding the reference again, to tell it you /really/ want to use it :)

    Or use System.Uri.UnescapeDataString, which I just found

    --
    Andrew

    • Marked as answer by TaubertRC Saturday, August 14, 2010 7:45 PM
    Saturday, August 14, 2010 7:34 PM
  • Sorry, it did work.  I initially missed the part about using HttpUtility.UrlDecode.  THAT worked.  System.Uri.UnescapeDataString also worked without adding any new references or imports.

    Where did you find these two goodies, because they are not in the originial link you posted.

     

    THANK YOU VERY MUCH.

    Saturday, August 14, 2010 7:44 PM
  • Can you recommend a good book on WPF.

    I am an ameteaur programmer using VB.net.  I can usually work with C# through a good convertor and can barely read C++.

    I have Pro WPF in VB 2010, but as usual, it leaves me with more questions than answers.  Also, what is the best forum for WPF questions?

     

    Thank you again.

    Saturday, August 14, 2010 7:49 PM
  • It was Lee who posted the link, not me. As for knowing about HttpUtility.UrlDecode, I've done a bit of ASP.NET too. I happened across System.Uri.UnescapeDataString when googling to see if anyone had reported problems using System.Web in Windows Forms.

    --
    Andrew

    Saturday, August 14, 2010 8:02 PM
  • I haven't used WPF yet, but the MSDN forum for it appears to be at
    Windows Presentation Foundation (WPF)

    where you could search for book recommendations. Or look at the reviews on (e.g.) Amazon.com.

    --
    Andrew

    Saturday, August 14, 2010 8:05 PM
  • I'll check out your suggestions.  Thanks again.

    The book I do have is 2-1/2" thick and I have barely made it through 3/8ths of an inch.  It is Sooooooooo different.

    Saturday, August 14, 2010 8:32 PM