• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 575
  • Last Modified:

Read unicode filenames and put it into a URL

I'm not very experienced with the multilingual/unicode aspects of Windows... so I'm not sure where to begin here.

I have a folder with a number of files in them. Some of the files have unicode names... some contain chinese characters and russian characters, etc.

So what I need to do is read in these file names into a string, such that I preserve the unicode values. Dir() is woefully inadequate for that ;) I think FindFirstFileW() can do it... but I haven't had any luck getting it to work and I feel like there ought to be a managed .NET way of doing this.

The next thing I need to do is pass this unicode string to a webpage, as a parameter in the URL. I don't need code to actually PERFORM the query to the website, I know how to do that. But I don't know how to format the url to include unicode characters. What kind of string would I need to pass as the url? Some kind of unicode string? Or do you convert the unicode characters into some kind of %U12423 type formatting?

I'm looking to do this in VB... whether it is VB.NET or VB6 all depends on which way would be simpler ;) I get the feeling this has already been done nicely in VB.NET I just don't know where it is.
1 Solution
Göran AnderssonCommented:
> whether it is VB.NET or VB6 all depends on which way would be simpler

Definitely VB.NET. String in .NET are always unicode, and there are classes for decoding a lot of different encodings.

Check if the System.IO.Directory.GetFile method gives you the correct file names. It would surprise me a bit if it didn't.

To encode the names to put them in an url, you use the System.Web.HttpUtility.UrlEncode method.

Dim files As String() = Directory.GetFiles("c:\somefolder")
Dim url As String = "http://www.somepage.com/somepage.aspx?file=" & HttpUtility.UrlEncode(files(0))

Open in new window

Frosty555Author Commented:
Yep perfect that worked well!

I knew it couldn't have been that hard ;)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now