Friday, August 26, 2011

C# function to clean file name

private string CleanFileName(string fileName)
{
string regexSearch =
new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
Regex r = new Regex(String.Format("[{0}]", Regex.Escape(regexSearch)));
return r.Replace(fileName, "");
}

Thursday, August 18, 2011

The remote certificate is invalid according to the validation procedure

Yesterday during my development, I have to use a web service on https in my C# program. I created my own self signed certificate with IIS 7. I installed it and then bammmm got this error "The remote certificate is invalid according to the validation procedure" while calling the web service.

The solution to fix this problem was a valid certificate for my machine.. but I was not able to create one... so Then I found the solution, that I can override certificate checking using the following code...

ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
bool validationResult = true;

//
// policy code here ...
//

return validationResult
};

Tuesday, April 26, 2011

C# array to comma separated string using String.Join

string[] ids = {"1","2","3"};
string connectedString = String.Join(",",ids);

Friday, March 18, 2011

Cannot pin my C# program in windows 7

Today I spent time wondering why everything else except one of my program can be pinned in Windows 7.

After surfing the web for a while I know that its name was restricted for pinning (why??).

Solution is here http://www.west-wind.com/weblog/posts/32765.aspx