C#下载ftp文件时文件名里含有特殊字符的处理方法

2024-12-26 14:31:50
推荐回答(2个)
回答1:

So it is probably just ANSI encoding, so try

var secureString = new SecureString();
            foreach (var b in Encoding.Default.GetBytes("C# test's file"))
                secureString.AppendChar((char)b);
            var stringResult = string.Empty;
            IntPtr bstr = Marshal.SecureStringToBSTR(secureString);
            try
            {
                stringResult =Marshal.PtrToStringBSTR(bstr);
            }
            finally
            {
                Marshal.FreeBSTR(bstr);
            }
            return stringResult;

回答2:

System.Web.HttpUtility.UrlEncode("你的uri")
需要添加System.Web.dll引用