Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Mar 22, 2011

GetCustomListTemplates returns 0 values

One of my colleague encountered this issue where he was trying to create list on feature activation based on a custom list template uploaded to the list template gallery.
We tried different ways to check why the GetCustomListTemplates method of SPSite retunred empty values even if there are custom list templates uploaded to the gallery.

It is because we didn't set the Version property while uploading the templates via Feature. SharePoint 2010 expects version to be '4' for the list template.
So this did the trick for us:




<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="TestModule1" Url="_catalogs/lt" List="114">
<File Path="TestModule1\MyList1.stp" Url="MyList1.stp" Type="GhostableInLibrary" IgnoreIfAlreadyExists="FALSE" >
<Property Name="Product Version" Value="4" />
</File>
</Module>
</Elements>



Resolution: Setting the 'Product Version' property of File object in the elements xml file to value '4' allowed us to access that template via GetCustomListTemplates property of SPSite object in SharePoint 2010

Feb 20, 2011

The remote certificate is invalid according to the validation procedure

When you get this error while trying to send email using gmail's account id and your own custom code, just paste below line before you call .Send method of the smtp client like this:

ServicePointManager.ServerCertificateValidationCallback =
                    delegate(object s,
                                X509Certificate certificate,
                                X509Chain chain,
                                SslPolicyErrors sslPolicyErrors) { return true; };

// write smtp client's .send here

Once you do this,  you will see the error disappears!

Jan 11, 2011

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine

If you happen to get this error when you are trying to import data from excel using a .net application , you need to install Microsoft Data Connectivity Components.

Resolution:
Install Microsoft Data Connectivity Components from here

External table is not in the expected format

I got this error while I was writing down a small utility to import data from excel. The error was in connection string which I used:
strdbConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
                                strFilePath
                                + "; Jet OLEDB:Engine Type=5;"
                                + "Extended Properties=Excel 8.0;";
 
Now I had windows 7 x64 bit and similarly Office 2010 professional plus and the above connection string didn't work.
Resolution:
Finally you need to use the following connection string in here:
 
strdbConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" 
+ strFilePath + 
";Extended Properties=Excel 12.0;";
 
And the error was resolved!

Oct 15, 2010

How to encrypt connection string in web.config

Lets say you want to encrypt the connection string you stored in the ''  element in your ASP.NET website's web.config file.
To encrypt the connection string, you have to use the 'aspnet_regiis' utility.
Open visual studio command prompt and type in the following line (obviously you'll have to provide  your website's path!)

aspnet_regiis -pef "connectionStrings" "fully-qualified-path-to-website-folder"
The above command will encrypt the web.config file at the location provided by you.

Now what if you want to roll back and decrypt the connection ?
Well then just open visual studio command prompt again and fire in this command:

 aspnet_regiis -pdf "connectionStrings" "fully-qualified-path-to-website-folder"
 Happy Coding!

Aug 6, 2010

Regular expressions for CSV File Parsing

I had a requirement to parse the csv file which was actually generated for reading in Excel into a c# application. The server didn't have any drivers for OLEDB/ODBC hence I did it with regular expressions
and here's a good link (http://www.blackbit.net/node/12) which has regular expressions for parsing comma and semicolon delimited records.