[DllImport("shlwapi.dll", CharSet=CharSet.Auto)]
static extern int UrlCreateFromPath(
[In] string path,
[Out] StringBuilder url,
[In,Out] ref uint urlLength,
[In] unit reserved
);
Declare Function UrlCreateFromPath Lib "shlwapi.dll" (TODO) As TODO
None.
Do you know one? Please contribute it!
The return string size will be INTERNET_MAX_URL_LENGTH (defined in wininet.h) or smaller.
Please add some!
[STAThread]
static void Main(string[] args)
{
Console.Write(@"Enter filename: ");
string filename = Console.ReadLine();
Console.WriteLine(UrlFromPath(filename));
Console.Read();
}
private static string UrlFromPath(string filepath)
{
uint maxLen=2048+32+3;//see INTERNET_MAX_URL_LENGTH
StringBuilder url = new StringBuilder((int)maxLen);
UrlCreateFromPath(filepath,url,ref maxLen,0);
return url.ToString();
}