June 2008

We had to download zip files from a FTP server, it was found that if the files were of small size there was no problem, however for big files (larger than around 4MB), after downloading them, it could not be opened and kept saying “the compressed zip folder is invalid or corrupted”.
The original code was:

FtpWebRequest reqFTP;
Response.Buffer = true;
Response.AddHeader(“Content-Disposition”, “inline; filename=” + filename);
Response.ContentType = “application/x-zip-compressed”;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(“ftp://” + ftpServerIP + “/” + filename));
reqFTP.Proxy = null;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword, ftpDomain);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
MemoryStream MemStream = new MemoryStream();
int bufferSize = 1024;
byte[] respBuffer = new byte[bufferSize];
int bytesRead = ftpStream.Read(respBuffer, 0, respBuffer.Length);
while (bytesRead > 0)
MemStream.Write(respBuffer, 0, bytesRead);
bytesRead = ftpStream.Read(respBuffer, 0, respBuffer.Length);
byte[] finalByte = MemStream.GetBuffer();

So, I changed the above 2 lines and wrote the below line which solved my problem.

I had to create a site definition for a blog site that I created so that it could be used as a template. My site had various custom webparts  and I also created some lists. So to incorporate all that I also used features. Here is a brief explanation of it:

Site Definitions are located in the following folder on the SharePoint server: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplatesThe aspx pages and various lists that make up the site definition are stored here.Inside the xml subfolder is the onet.xml which contains the various configurations and modules of the site definition like the various web part zones in the pages.


1.       First I traversed to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplatesCopied the Blog folder and pasted it back, renamed it to SampleBlog.

2.       Next, connect the new site definition to sharepoint by copying the WEBTEMP.XML file in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML” and paste it to the same location renaming it as webtempSampleblog.xml.

Open the file and delete any unnecessary <template> tag as shown below:

<?xml version=”1.0″ encoding=”utf-8″?>

<!– _lcid=”1333″ _version=”12.0.4518″ _dal=”1″ –>

<!– _LocalBinding –>

<Templates xmlns:ows=”Microsoft SharePoint”>

 <Template Name=”SampleBlog” ID=”1333″>

    <Configuration ID=”0″ Title=”Sample Blog Template” Hidden=”FALSE” ImageUrl=”/_layouts/images/BLOGPREV.PNG” Description=”Sample blog template” DisplayCategory=”Sample Templates”></Configuration>



Change the name attribute to “Sample Blog Template” and the ID so that it is unique, generally numbers above 1000 will be safe.

3.       Reset IIS.

4.    Customizing the site definition.

After this point, one can see the new site definition and create new sites,but we want to customize our site definition, add various web parts etc.To do that we need to change the ONET.XML

The <Module> is created  for various pages.Inside that is <View> which represents various web part zones of the page. So, I exported the webparts and copied the xml’s in respective <View> tags representing the proper zone.

My next challenge was  with copying the xmlof DataView Web parts, as by default  Sharepoint Designer binds the control to the list instance using the list instance GUID. So, it is difficult to create a new site using this template along with the GUID’s of the DataView Web Part.

So, we need to replace the GUID’s with the list names.

i) On the attributes of the DataFormWebPart element replace the attribute ListName=”{GUID}” by ListName=”LIST_NAME” where LIST_NAME is the name of the list that you are binding to.

ii) Go through all of the DataFormParameter elements and replace:   

    <WebPartPages:DataFormParameter Name=”ListID” ParameterKey=”ListID” PropertyName=”ParameterValues” DefaultValue=”{GUID}”/>


<WebPartPages:DataFormParameter Name=”ListName” ParameterKey=”ListName” PropertyName=”ParameterValues” DefaultValue=”LIST_NAME”/>

iii) Go to the ParameterBindings element and replace

    <ParameterBinding Name=”ListID” Location=”None” DefaultValue=”{GUID}”/>


    <ParameterBinding Name=”ListName” Location=”None” DefaultValue=”LIST_NAME”/>   

This should give you a GUID free DataForm webpart that can be placed on a page layout used by multiple sites on your site collection (as long as the name of the list is the same on all sites).


I had created several lists in my site, so to include those while I create a new site from my site definition, I had to use features.

To implement a feature we need to create a folder in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES

So, I created one named SampleBlogSite, and here is the content:

<Feature Id=”67409a48-46c8-4a28-8f2e-bca0a56e4213″


  Title=”Sample Blog Site”


  ReceiverAssembly=”Sample.Blog.FeatureDefinition, Version=, Culture=neutral, PublicKeyToken=246c59317fd65cd2″


  Description = “Activate this feature to convert current blog site to Sample Blogs site. this feature can only be activated to a blogs site defintion.”



Here, Sample.Blog.FeatureDefinition is the dll  implementing the feature.

Create a class inherited from SPFeatureReceiver. Implement the methods FeatureActivated, FeatureDeactivating, FeatureInstalled and FeatureUninstalling by overriding the base methods.

Write your code into the FeatureActivated-method.

Now change your feature.xml in the props ReceiverClass and ReceiverAssembly and set the corresponding values there for your assembly.

Refer this feature from your ONET.XML, as:

<Feature ID=67409a48-46c8-4a28-8f2e-bca0a56e4213 />

So, this completes the entire process.

I needed to add a populate on demand treeview to a div because the normal treeview was taking a very long time to get loaded. This is what I did.

public System.Web.UI.WebControls.TreeView tvGeoScope = new System.Web.UI.WebControls.TreeView();
string strCountry =”Country”;
tvGeoScope.ID =”tvGeoScope”;
//gets called whenever a node is clicked to expand.
tvGeoScope.TreeNodePopulate += new TreeNodeEventHandler
TreeNode n2 = new TreeNode(strCountry, strCountry);
n2.Expanded = false;
n2.SelectAction = TreeNodeSelectAction.None;
n2.PopulateOnDemand = true;
n2.ShowCheckBox = false;

To get a more detailed explaination, click on the link where I have given more explainations http://www.dotnetspider.com/resources/20921-Get-populate-demand-treeview-asp-net.aspx

I faced a typical problem while uploading files in a FTP server, it worked fine in the development server, however, when I deployed it in the production environment, it came up with an error “The Requested FTP Command is not supported when using HTTP proxy.”                                                                                 

 To solve this problem we have to set the proxy method of FTPWebRequest to null.

I faced a typical problem where I had to implement a tab control using AJAX in a sharepoint site. When I tested it in sharepoint, I found that only the first time click of the tab buttons was working. When I clicked for the first time in a tab button it was working but when I clicked the second time it wasn’t.

To solve this problem, I wrote a method which will reset the form action as there is a sharepoint script included for changing the form action which may stop the form submission.

//Fixing Form Action
        private void FixFormAction ()
            if (this.Page.Form != null)
                string formOnSubmitAtt = this.Page.Form.Attributes[“onsubmit”];
                if (formOnSubmitAtt == “return _spFormOnSubmitWrapper();”)
                    this.Page.Form.Attributes[“onsubmit”] = “_spFormOnSubmitWrapper();”;
            ScriptManager.RegisterStartupScript(this, typeof(AjaxWebPart), “UpdatePanelFixup”, “_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;”, true);

Or u can add the following after<@%Register> tag in your user contol
<script type=’text/javascript’>_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;</script>

which also does the same thing.