Alik Levin's

Clarity, Technology, and Solving Problems | PracticeThis.com 

March, 2010

  • Alik Levin's

    Getting Started Building Web Parts in SharePoint 2010

    • 0 Comments

     Alik Levin    I followed the instructions provided in Module 1: Getting Started Building Web Parts in SharePoint 2010 webcast. This webcast teaches the following:

    • Create standard ASP.NET Web Parts for SharePoint 2010.
    • Create Visual Web Parts for SharePoint 2010.
    • Use SharePoint controls and data in Web Parts.

    Quick Resource Box

    The following walkthrough assumes you have Sharepoint 2010 Foundation installed on your dev station. Otherwise consider following the steps outlined in Setting Up the Development Environment for SharePoint Foundation on Windows 7.

    Step-by-step Walkthrough

    • Open Visual Studio 2010 in elevated mode.
    • Click “New Project” on Start Page.
    • Under “Installed Templates”,  Expand Sharepoint node and choose 2010.
    • Choose “Visual Web Part” project template, name it MyVisualWebPartProject or any other to your desire.
    • Click OK. Specify your computer name where Sharepoint installed (for example, http://alikl14/) and click Finish button.
    • Drag treeview control onto VisualWebPart1UserControl.ascx at the end of the file, it should look similar to this:

    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14..." %
    <%@ Register Tagprefix="SharePoint..." %>

    ...

    <%@ Control Language="C#" AutoEventWireup="true..." %>
    <asp:TreeView ID="siteStructure" runat="server">
    </asp:TreeView>

    • Open the VisualWebPart1UserControl.ascx.cs file
    • Add the following using statement at the top:

    using Microsoft.SharePoint;

    • Add the following code to the Page_load event handler:

                SPWeb thisWeb = null;
                try
                {
                    TreeNode node;
                    thisWeb = SPContext.Current.Web;
                    node = new TreeNode(thisWeb.Title, null, null, thisWeb.Url, "_self");
                    siteStructure.Nodes.Add(node);
                    TreeNode parentNode = node;
                    foreach (SPList list in thisWeb.Lists)
                    {
                        if (!list.Hidden)
                        {
                            node = new TreeNode(list.Title, null, null, list.DefaultViewUrl, "_self");
                            parentNode.ChildNodes.Add(node);
                        }
                    }
                    foreach (SPWeb childWeb in thisWeb.Webs)
                    {
                        addWebs(childWeb, parentNode);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    thisWeb.Dispose();
                }

    • Add also the following function to the file:

            private void addWebs(SPWeb web, TreeNode parentNode)
            {

                TreeNode node;
                node = new TreeNode(web.Title, null, null, web.Url, "_self");
                parentNode.ChildNodes.Add(node);
                parentNode = node;
                foreach (SPList list in web.Lists)
                {
                    if (!list.Hidden)
                    {
                        node = new TreeNode(list.Title, null, null, list.DefaultViewUrl, "_self");
                        parentNode.ChildNodes.Add(node);
                    }
                }
                foreach (SPWeb childWeb in web.Webs)
                {
                    addWebs(childWeb, parentNode);
                }

     

    • Build the project
    • In the solution explorer right click MyWebPartProject and choose “Deploy”.
    • Navigate to your Sharepoint using browser, in my case http://alikl14/
    • Switch to “Edit” mode – click on notepad like icon on up right corner.
    • Click on “Insert” under “Editing Tools”.
    • Click on “Web part”.
    • Click on “Custom” on the left.
    • Choose VisualWebPart1 and drag it on the page.
    • Click “Save” [diskette icon].
    • You should see the tree view control displaying your Sharepoint content.

    Related Books

  • Alik Levin's

    Setting Up the Development Environment for SharePoint Foundation on Windows 7

    • 0 Comments
     Alik Levin    This post is a summary of steps I have taken to set up a development environment for Sharepoint Foundation on Windows 7. It generally distilled from Setting Up the Development Environment for SharePoint Foundation

    Quick Resource Box

    Step-by-step walkthrough

    • Install WCF Hotfix for Windows (KB976462)
    • Create c:\SharePointFiles\ folder
    • Download Sharepoint Foundation 2010 beta to the folder.
    • Extract Sharpoint files by running this command: c:\SharePointFiles\SharePoint /extract:c:\SharePointFiles
    • Add <Setting Id="AllowWindowsClientInstall" Value="True"/> to c:\SharePointFiles\files\Setup\config.xml
    • Install Microsoft FilterPack 2.0 Beta by running this command: c:\SharePointFiles\PrerequisiteInstallerFiles\FilterPack\FilterPack.msi
    • Install Microsoft Sync Framework
    • Install SQL Server Native Client
    • Install Microsoft Geneva Framework Beta 1 Runtime for x64
    • Install ADO.NET Data Services v1.5, Runtime Only installer.
    • Execute this commands in command prompt [should be one liner]:

      start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-ApplicationDevelopment;IIS-ASPNET;IIS-NetFxExtensibility;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-HttpTracing;IIS-CustomLogging;IIS-ManagementScriptingTools;IIS-Security;IIS-BasicAuthentication;IIS-WindowsAuthentication;IIS-DigestAuthentication;IIS-RequestFiltering;IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;IIS-WebServerManagementTools;IIS-ManagementConsole;IIS-IIS6ManagementCompatibility;IIS-Metabase;IIS-WMICompatibility;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI;WCF-HTTP-Activation;WCF-NonHTTP-Activation

    • Reboot
    • Start installation by running this command: c:\SharePointFiles\Setup.exe
    • Do not proceed with the configuration wizard when prompted. Stop here:

    Setting Up the Development Environment for SharePoint Foundation on Windows 7

    Related Books

  • Alik Levin's

    ASP.NET Performance: Get Rid of HTTP 401 and HTTP 304

    • 0 Comments
     Alik Levin    Making fewer calls to IIS web server improves your ASP.NET application’s performance, or more precisely, it improves UI responsiveness or, even more precisely, it improves UX, the User Experience. Better User Experience leads to better adoption. 

    Quick Resource Box

    In this post I will share how to improve User Experience by reducing the number of HTTP 401 and HTTP 304 responses.

    The Impact of HTTP 304

    In general HTTP 304 is returned by web server when the browser is not really sure about up-to-date’ness of the resource. Imagine this conversation:

    1. Browser: “Hey, IIS web server, I have this GIF file in my cache stored locally. I stored it here since my last visit to your page. Not sure it’s up-to-date. Should I use it? Or, do you have a newer version?”
    2. IIS web server: “HTTP 304. Nope, there is no newer version down here in the data center. Use your locally cached version of the GIF.”
    3. Browser displays the GIF from local cache.

    This one extra roundtrip might look very subtle in case when there are very few static elements on the page. In case there are many static elements on the page the User Experience can be severely affected. Below is an extreme example of HTTP 304 responses captured by Fiddler. All the images in the diagram are stored in local cache but they never displayed right away – Browser first consults with the server and gets HTTP 304 before displaying it:


    image

    The Impact of HTTP 401

    HTTP 401 returned when Browser requests a resource that requires authentication. The fact that the resource requires authentication results in two HTTP requests – initial requests gets HTTP 401 asking for credentials, and subsequent request is satisfied with the actual response after the creds were validated. Something similar to this:

    image 

    Imagine now situation that static resources such images, JavaScript, CSS files, etc require authentication. Usually these guys are the same for every user and there is no point to require authentication/authorization for it, right? If so then there is no need to waste another HTTP 401 roundtrip for them, right?

    Improve Performance by Partitioning Your Application

    Consider the following solution structure:

    image

    Notice the following four folders: CSS, IMG, JS, and Restricted. The first three contains static style sheets, images, and JavaScript files respectively. The Restricted folder contains all the dynamic ASPX pages that implement your scenarios referencing the static content from the other three folders when needed. The web.config file looks as follows:

    <?xml version="1.0"?>
    <configuration>
        <system.web>
          <authorization>
            <allow="*"/>
          </authorization>
        </system.web>
      <location path="Restricted">
        <system.web>
          <authorization>
            <deny="?"/>
          </authorization>
        </system.web>
      </location>
    </configuration>

    This configuration achieves the following:

    1. Static files served from publically accessible location that way we avoid HTTP 401 extra roundtrips.
    2. System administrators are not required to fish the static files across the solution’s file structure just to set expiration policy – there are only 3 folders to specify it so there is a better chance it will happen. It should help reducing HTTP 304 extra roundtrips.

    Related Books

Page 1 of 3 (8 items) 123