Monday, May 31, 2010

Allow the code block in sharepoint

In the web.config file in the SharePoint virtual directory contains the following section:
  <SharePoint>
    <SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
      <PageParserPaths>
      </PageParserPaths>
    </SafeMode>
    :
  </SharePoint>

     

       
By default the node is empty. You can add nodes to specify the virtual paths where you want to allow server side scripts:
<PageParserPaths>
        <PageParserPath VirtualPath="/pages/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/>
</PageParserPaths>

       

Where CompilationMode is one of the following values:


       

Always The page should always be compiled (default value)
Auto ASP.NET will not compile the page, if possible. 
Never The page or control should never be dynamically compiled.

Thursday, May 20, 2010

Deploy WebPart as Feature with CAS

Introduction

I had started writing this blog over a year and half ago but I had hirer priority things come up. I still find that a lot SharePoint developers have challenges understanding how to deploy web parts. Specifically CAS, GAC vs bin, rely on CodePlex tools, etc. are a common issue.

As a SharePoint consultant I have seen many struggle with web parts. The issue is not usually with the development of a web parts. There are lots of blogs and books written that show how to develop web parts but the biggest issue I have seen is correctly deploying of web parts. More specifically:

* Creating web part deployment solutions
* Deploying web parts as a feature
* Deploying the web parts in a secure fashion

With Visual Studio 2005, there was a plug-in that developers used to quickly deploy web parts out to a SharePoint environment however there was no control over the deployment package or the deployment process. This plug-in was great for development environments because it allowed developers to quickly deploy and iteratively debug web parts however developers would continue to use this deployment for production deployments. This caused many issues with the control, configuration and change management issues down the road.

With Visual Studio 2008, there is better tooling has been incorporated into Visual Studio by Microsoft for the creation of SharePoint web part projects.

Other tools have been created to help with the authoring WSP deployment files such as WSP Builder. This tool works pretty well but knowing how a WSP solution file is created is equally important. What I have seen is that developers become so dependent on tools such as these, they do not have an understanding of how web parts actually work.

Still the biggest issue we see with deployment is developers run into challenges with deployments of their web parts and they quickly do the following:

* They raise the trust level on their SharePoint environments to either Medium or Full.
* They deploy the web part DLL directly to the GAC.

Both are unacceptable solutions especially when this is a production environment (Intranet or not). What makes this worse is many forums, blogs, etc. usually state to do as such and do not outline the consequences. As well, I have not seen any truly good end to end discussions of this topic.

In this blog I will take a deep dive into how a web part should be properly deployed. The web part that will be developed will be inconsequential ("Hello World" example) because the focus will be on deployment. I will specifically focus on:

* Deploying a web part as a Feature.
* Deploying to web bin directory.
* Code Access Security (CAS).

A lot of this information will become moot because we are expecting the next release of Visual Studio to fix a lot of these gaps and provide all the tooling to build SharePoint deployment packages end-to-end.

The first part of this blog is going to discuss how to create a web part feature and properly deploy it. The interesting stuff about properly setting up CAS will later on. However I believe it is important to understand the entire picture before we jump into CAS with web parts.

Creating a Web Part Project

In this first project I am going to create a basic web part project using no accelerator tools.

* Create a C# code library project which I named WSSDistillery.Deploy.WebPart.
* Add a references to Microsoft.SharePoint and System.Web.
* In the AssemblyInfo.cs you will need to add [assembly: System.Security.AllowPartiallyTrustedCallers]. This will allow SharePoint to call the web part contained within dll.
* Go into the properties of the project and sign the assembly.
* Renamed Class1.cs to something else. I renamed it to SimplePart.cs.
* Add an XML file called manifest.xml.
* Add a file called WSP.ddf.
* Add the following three folders. First "TEMPLATE", then beneath it "FEATURES", then beneath it "WSSDistillery.Deploy.WebPart".
* Under the "WSSDistillery.Deploy.WebPart" folder add the following files elements.xml, Feature.xml and WSSDistillery.Deploy.WebPart.SimplePart.webpart.

It is pretty simple to throw together even without all of these tools out there. The final solution should look like:



I will go into further detail about each file and what goes into them. Some initial notes are:

* It is common practice to create a hierarchy of folders in the Visual Studio project based on the folder hierarchy of files in the 12 Hive (\\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES).
* I named the folder "WSSDistillery.Deploy.WebPart" because this is the folder that will be deployed into SharePoint. I put the namespace into the name of the folder to lower the chances of a name conflict for other SharePoint Features that may be created over time.
* Even though the assembly has been signed, it will not be deployed to the GAC.

Creating the Web Part

I mentioned before, this will not be a lesson on how to develop a web part. As such, this web part is going to be a simple implementation; Hello World for now. I will add some code later which will require it to have a CAS policy.

public class SimplePart : System.Web.UI.WebControls.WebParts.WebPart
{
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);

writer.WriteLine("Hello World");
}

}

Get DLL Strong Name

Might as well go ahead and get this now, because this will be needed in several places. Open the Visual Studio command prompt and run the following command:

* Sn –Tp [path]\[dll name]
* sn -Tp "C:\WSSDistillery\Deploy\WSSDistillery.Deploy\WSSDistillery.Deploy.WebPart\bin\Debug\WSSDistillery.Deploy.WebPart.dll"

Two values will be generated. The first is a Public Key which is really long, go ahead and get that. The second is a Public Key Token which will be used in several places. These will be used in some of the files that will be created next.

Webpart File

I know "WSSDistillery.Deploy.WebPart.SimplePart.webpart" is a long filename. Again, it is good practice to have the namespace in the name of the file to ensure there are no name conflicts down the line during your web part deployments. This file will be deployed into the Web Part Gallery within a site collection. This file has a reference to the DLL that has the web part code. As well, the Data XML elements contain the text that a user will see when adding a to a web part page within SharePoint. A good description here of what the web part is required for the users of SharePoint.


Cannot import WSSDistillery.Deploy.WebPart.SimplePart

Simple Web Part
This is a very simple web part for demonstrating deployments.


<webParts>
    <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
        <metaData>
            <type name="WSSDistillery.Deploy.WebPart.SimplePart, WSSDistillery.Deploy.WebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aa9a1a08fbf22452" />
            <importErrorMessage>Cannot import WSSDistillery.Deploy.WebPart.SimplePartimportErrorMessage>
        metaData>
        <data>
            <properties>
                <property name="Title" type="string">Simple Web Partproperty>
                <property name="Description" type="string">This is a very simple web part for demonstrating deployments.property>
            properties>
        data>
    webPart>
webParts>


elements.xml File

This file will be responsible for deploying the WSSDistillery.Deploy.WebPart.SimplePart.webpart file to the Web Part gallery in the site collection.



xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="WebParts" List="113" Url="_catalogs/wp">
        <File Url="WSSDistillery.Deploy.WebPart.SimplePart.webpart" Type="GhostableInLibrary" />
    Module>
Elements>


Feature.xml File

This is a standard SharePoint Feature file. There are references to both elements.xml and WSSDistillery.Deploy.WebPart.SimplePart.webpart files ion the ElementManifests.


xml version="1.0" encoding="utf-8" ?>
<Feature Id="8CD4DE2E-353E-40e1-A2AB-8004F6E8AA5F"
    Title="Simple Web Part"
    Description="This is a very simple web part for demonstrating deployments."
    Version="1.0.0.0"
    Scope="Site"
    Hidden="FALSE"
    DefaultResourceFile="core"
    xmlns="http://schemas.microsoft.com/sharepoint/">
    <ElementManifests>
        <ElementManifest Location="elements.xml" />
        <ElementFile Location="WSSDistillery.Deploy.WebPart.SimplePart.webpart"/>
    ElementManifests>
Feature>




<Solution xmlns="http://schemas.microsoft.com/sharepoint/" SolutionId="052C7D59-7DCF-4782-93B4-51C3F6DECF3B">
    <FeatureManifests>
        <FeatureManifest Location="WSSDistillery.Deploy.WebPart\Feature.xml"/>
    FeatureManifests>
    <Assemblies>
        <Assembly Location="WSSDistillery.Deploy.WebPart\WSSDistillery.Deploy.WebPart.dll" DeploymentTarget="WebApplication" >
            <SafeControls>
                <SafeControl Assembly="WSSDistillery.Deploy.WebPart.SimplePart, WSSDistillery.Deploy.WebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aa9a1a08fbf22452"
                             Namespace="WSSDistillery.Deploy.WebPart"
                             Safe="True"
                             TypeName="*"/>
            SafeControls>
        Assembly>
    Assemblies>
Solution>

 
<trust level=" WSS_Minimal" originUrl="" />




<PermissionSet   class="NamedPermissionSet" version="1" Name="SPRestricted">
<IPermission  class="AspNetHostingPermission"  version="1" Level="Minimal" />
<IPermission class="SecurityPermission" version="1" Flags="Execution" />
<IPermission class="WebPartPermission" version="1" Connections="True" />
PermissionSet>

<IPermission class="SharePointPermission" version="1" ObjectModel="True" />

<IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, Pub

<Solution xmlns="http://schemas.microsoft.com/sharepoint/" SolutionId="052C7D59-7DCF-4782-93B4-51C3F6DECF3B">
    <FeatureManifests>
        <FeatureManifest Location="WSSDistillery.Deploy.WebPart\Feature.xml"/>
    FeatureManifests>
    <Assemblies>
        <Assembly Location="WSSDistillery.Deploy.WebPart\WSSDistillery.Deploy.WebPart.dll" DeploymentTarget="WebApplication" >
            <SafeControls>
                <SafeControl Assembly="WSSDistillery.Deploy.WebPart.SimplePart, WSSDistillery.Deploy.WebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aa9a1a08fbf22452"
                             Namespace="WSSDistillery.Deploy.WebPart"
                             Safe="True"
                             TypeName="*"/>
            SafeControls>
        Assembly>
    Assemblies>
    <CodeAccessSecurity>
        <PolicyItem>
            <Assemblies>
                <Assembly PublicKeyBlob="00240000048000009400000006020000002400005253413100040000010001
00ad51a9cdfbe7db0a0f6d16a257d874a19993707b1bb0e873bda1c18c5b1592e24070f57b637
e0be2b00790fd67bc3e0c61205af5c0e5753780f257acb2c0b4b4830e23ace37be05c7ab52478
2731f85786d7648e6e14a99a83dc474081d5cf5e1fc1b20da22fc3b5a94b44ad3903aa8f081cc
0508e71b5606927824114f2ecd1" />
            Assemblies>
            <PermissionSet class="NamedPermissionSet" Name="WSSDistillery.Deploy.WebPart" version="1" Description="WSSDistillery.Deploy.WebPart">
                <IPermission class="AspNetHostingPermission" version="1" Level="Minimal" />
                <IPermission class="SecurityPermission" version="1" Flags="Execution" />
                <IPermission class="WebPartPermission" version="1" Connections="True" />
                <IPermission version="1" class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ObjectModel="True" />
            PermissionSet>
        PolicyItem>
    CodeAccessSecurity>
Solution>

Sharepoint


 

 

What are Sharepoint Content Types?



For me, one of the coolest new features of SharePoint Server 2007 (or MOSS) is Content Types. In this article, I’ll aim to give a brief overview of what they are and why you should be getting excited about them (especially if you are from a SharePoint 2003 background).

It is worth noting that this article is focused on the implications of Content Types in a document management scenario. Content Types are used throughout MOSS and have benefits throughout, but it was too much to cover in one article, so I decided to focus on DM.
What is a Content Type then?
A content type is an object that is stored within MOSS that defines several elements of a piece of content, including:

  • Document Template that the content will be based on
  • Columns that the content will have associated with it (metadata)
  • Workflows that the content will use
  • Information Management policies that apply to the content
  • Conversion types for the content



    ASP.NET 2.0 Web Part Vs SharePoint based Web Part

    ASP.NET 2.0 Web Part
  • For most business needs.
  • To distribute your Web Part to sites that run ASP.NET 2.0 or SharePoint sites.
  • When you want to reuse one or more Web Parts created for ASP.NET 2.0 sites on SharePoint sites.
  • To use data or functionality provided by Windows SharePoint Services 3.0. For example, you are creating a a Web Part that works with site or list data.

SharePoint-based Web Part
  • When you want to migrate a set of Web Parts using the SharePoint-based Web Part infrastructure to Windows SharePoint Services 3.0.
  • To create cross page connections.
  • To create connections between Web Parts that are outside of a Web Part zone.
  • To work with client-side connections (Web Part Page Services Component).
  • To use a data-caching infrastructure that allows caching to the content database.



  • SharePoint Database Structure and Its Usage






    SharePoint uses SQL Server technology as to store information such as site configuration and site content. You should consider carefully whether you need to access the database directly or not. Microsoft has strongly suggested that we should not access data directly from the DB.
    "Customers are strongly advised against direct access in a read-only manner to these DB unless Microsoft protocol documentation is followed exactly. Accessing these DBs programmatically or manually could cause unexpected locking within Microsoft SQL Server that can result in overall performance problems."
    Many people out there in the community disagree that there are harm in reading data directly from the table as reading the database would cause no data change or its structure change.
    Typically when SharePoint is first installed it generates two DB. One is configuration DB and the other one is the content DB. The configuration database normally has a default name of Sharepoint_config and and content has a default name of wss_contnet.
    Sharepoint_config: this is the configuration db that contains information about the moss server, SQL Server, farm configuration, patches, updates, users, security, custom templates, features and etc. Typically it has around 24 tables. You can find more about what these tables does in this article.
    WSS_Content: The content database typically holds information about activated features for site, site collections, web page information, users related to site, groups, roles, membership, user subscriptions, role assignment and etc.
    Keep in mind that when updating the database directly always uses the SharePoint API object Model. Before doing any update consider doing a backup of the SharePoint database.


    Move a list using a list template.

    We can move a list using a list template.

    1. Save the list as a template from the source list (make sure to include the contents)...save the template file on your local machine.
    2. Import the template to the list templates gallery on the source site.
    3. Create a list from the newly imported template.
    4. Delete the template from the list templates gallery if you no longer need it.

    Much easier...and like everything else that can be done through the UI.





    Sharepoint CSS Options with Master Pages

    SubmittedBy:  CI-tech1
    Description:


    Skinning a SharePoint 2007 site with Master Pages is by no means and open/shut case of altering the look and feel of a site.  There are some CSS inheritance issues that have to be contended with first.
    As a quick refresher, styles applied to elements in a page will be styled according to the last property that was applied to it.   An inline style will override a style listed in the HEAD tag or in a linked CSS file.  Additionally, you can selectively override style properties by selectively listing what should be overridden.  For example:
     

     
    In this sample, the body style of the page will be white with no margins because the inline style only overrode the background property.
    This overriding facet of CSS is key in SharePoint.  Being 100% aware of what style sheets are called where can really help decrease the number of headaches you incur while trying to figure out why your custom styles are not appearing in your site.
    Here is a general breakdown of how styles are pulled into a rendered SharePoint page in regards to master pages:
    • If your master page links to a custom CSS file, the CSS file will get pulled BEFORE CORE.CSS.
    • If your master page links to a CSS file, and CORE.CSS has been unghosted for the site, the custom CSS file will get pulled AFTER CORE.CSS.
    • If you specify a custom CSS file in the Master Page settings (Site Actions/Site Settings/Master Page), the custom CSS file will get pulled AFTER CORE.CSS. Note: CSS overrides and new styles will also be applied to _layouts pages.
    • Any styles listed or linked to in the PlaceHolderAdditionalPageHead ASP content placeholder will get pulled AFTER CORE.CSS.   Problem with this approach is you will have to list your styles or link to your custom style sheet in every page layout file you create.
    • Styles listed in the master page file (not linked to, actually listed out in a set of STYLE tags beneath the links to CSS files) will be called AFTER all links to CSS files, including CORE.CSS.
    • Master pages deployed via a Feature will call CORE.CSS AFTER the custom CSS file(s).
    So if you want to override any styles that are listed in CORE.CSS (and you will be if you are skinning your site), you will need to do one of the following:
    • List the styles in the master page file
    • Link to the style sheet through Master Page settings
    • Include the styles in the PlaceHolderAdditionalPageHead ASP content placeholder in your page layout files
    • Unghost CORE.CSS for the site.    I don't recommend this.
    My recommendation is to store styles in the master page itself in a set of STYLE tags.  If your master page design has variations for assorted subsites, store the CSS differences in a file and reference it via the Master Page settings, or if you need CSS changes for a single page, store it in an HTML file and reference it in a hidden Content Editor Web Part.



    Set up announcements to disappear from the screen when they pass their expiration date

    SubmittedBy:  CI-tech1
    Description:


    Note: This does not apply to the expanded view of the announcements web part. In the expanded view you can still access all announcements until they are permanently deleted manually.
    1. For Portal: Select Edit Page under the Actions menu; Select the arrow to the right of the announcements title bar and select Modify Shared Web Part.
      For WSS Site: Select the arrow to the right of the announcements title bar and select Modify Shared Web Part.
    2. Under Selected View, select Edit the Current View.
    3. Under Filter, select these options:

      1. Select Show items only when the following is true:
      2. Under Show the items when column, in the first drop down select Expires.
      3. In the second drop down select is greater than or equal to.
      4. In the field, enter [Today].
    4. Select OK.


    5. MOSS Enterprise Search - 16 things you might not know

      SubmittedBy:  CI-tech1
      Description:




      Hello everybody \o/ - a few bits and pieces you might find useful when designing and deploying Enterprise Search based on Office SharePoint Server 2007 .
      Really interesting things
    6. On document libraries which support approval, users might be able to search and view abstracts for unpublished content which they would otherwise not be able to see. This happens if the crawler account has permission to view drafts, which is separate from any security trimming which will be applied. Using an account with only reader permissions would prevent this, but conversely a user with rights to see draft content could only search content from the last published version. Since the files share a URL it's either one or the other - a decision to be made by your customer.
    7. Keyword search has moved from implicit OR to implicit AND as standard, although this can be configured on calls through the web service. Additionally,  if you use the Advanced Search, which in effect creates a SQL query, you can specify to AND or OR your requests as well as wildcard your keywords, etc.
    8. Only a full crawl will re-index ASPX files. Therefore, if you have removed documents from a document library, the library may still appear in the results if you search for the document name after an incremental crawl.
    Capacity
    • There is a tested recommended maximum of 4 SSPs per farm, and a hard limit of 20.
    • The tested recommended maximum is 50 million documents across all content sources in an index. Since you can have only one index server per Shared Services Provider, the recommended approach for more capacity is to add another SSP. There is no supported way to union the results. Don't forget BDC items count to your total.
    • There is a hard limit of 500 start addresses per content source. If the default content source is full, additional new sites will not have their start addresses registered (anywhere), so you'll need to add them manually to another content source, or change the default content source.
    • Information about the size of search indexes and search databases relative to corpus size is due to be released on Technet shortly.
    Configuration and topology
    • Since the Indexer crawls a Web Front End for SharePoint content, in a load balanced scenario, any of the Web Front End servers could get hit. You can override this and specify a single WFE for the Indexer to use. In this case, you could exclude this from the load balancer and have it as a dedicated WFE for indexing.
    • Query and Index roles can run on the same server. However, to add extra Query servers, the Indexer must run alone. E.g. you would scale out from Query+Index on one server to Index on one server and Query on two servers.
    • Collapsing your WFE and Query roles onto the same server can improve query performance, especially when custom security trimmers are used on the WFEs to iterate over the results.
    • Architectures can be mixed between roles (e.g. 32bit WFE, 64bit Indexer) but not in the same role.
    • 64bit is recommended for the Indexer, but most custom IFilters, like Adobe PDF, don't support this new platform just yet.
    Crawling and Querying
    • The default maximum file size the Indexer will download and parse is 16mb. This is a registry entry on the Indexer - one to update if customers deal with large PowerPoint slidedecks etc.
    • Search term word stemming is off by default. You can enable this in the Core Search Results web part, but it may skew the new improved ranking mechanism.
    • Search usage reports gather data from client side asynchronous JavaScript when a user selects a result from the results page. Therefore, reports don't show search terms used through the API or the Query Web Service.
    • It's kind-of obvious, but forms authentication to external websites is not supported for crawling.


    Fill Dropdown List with SharePoint List Items


    protected void Page_Load(object sender, EventArgs e)
    {
                SPSite mySite = new SPSite(“http://server/sites/site“);
                SPWeb myWeb = mySite.OpenWeb();
                {
                         SPList myList = myWeb.Lists["ListNameHere"];
                         foreach (SPListItem listRecords in myList.Items)
                        {
                                    ListItem tempItem = listRecords["FieldNameHere"].ToString();
                                    ddlFromSPList.Items.Add(tempItem);  //ddlFromSPList is the name of the dropdown list
                        }
               }
    }
    ———————————————————————————————————————————————   
          
    private void buildList(DropDownList list, DataSet myDataSet)
    {
           foreach(DataColumn dCol in myDataSet.Tables[0].Columns)
          {
                 if (dCol.ToString() != “”)
               {
                        ListItem tempItem = new ListItem(dCol.ToString());
                        list.Items.Add(tempItem);
               }
               else
              {
                  break;
              }
         }
    }


    Creating Custom Templates


    Now that we know that custom templates track changes to a SharePoint site definition, we can examine the different types of custom templates. List templates track changes to columns, forms, pages, and optionally, changes to the content associated with a specified list. Site templates track changes to site navigation, Web Parts, lists present on a site, and optionally, changes to the content of a single site. You can save an existing site as a site template.
    Note   There is a 10 MB quota on the total size of the content you can store in a site template. You can determine the size of site content by going to Top-Level Site Administration, and in the Management and Statistics section, clicking View site usage data.
    A custom template is persisted as a file with an .stp extension, which is actually a .cab file that you can rename with the .cab file extension and open in Windows Explorer. This file includes one Manifest.xml file in Collaborative Application Markup Language (CAML) that the server generates as a subset of the Microsoft SharePoint Migration Tool (Smigrate.exe) manifest file format.
    Let's say that you created a site, customized it by adding lists, events, document libraries, custom Web Parts, and applied a special theme. You want to share this piece of work with other site owners or impose this site template on any subsites. On the Site Settings menu, click Go to Site Administration, and then in the Management and Statistics section, click Save as template. Type a file name using an .stp extension and type a title and description for your site template. You can also select the Include content check box. You save your site as a template in a gallery inside the content database to make it available to other subsites. As long as subsequent subsites are based on the same site definition (for example, on a Document Workspace) and have the identical language of the original site, you can create subsites using this template.
    To make the template appear in the list of templates in the Site Creation wizard, you need to export the template to the file system and run the STSADM command tool. To export the template, right-click the template and click Save Target As, and then follow the prompts to save the template. After saving the template to the file system, from a command prompt, type the following:
    stsadm.exe -o addtemplate -filename "local_drive:\site_template_file_name.stp" -title "Site_Template_Name"
    Note   You must reset Microsoft Internet Information Services (IIS) before these changes can take affect. After resetting IIS, the Site_Template_Name template becomes available in the site template list during site creation.
    You can also export a list template the same way you exported the site template. However, list templates are available only to the site collection of the site from which you exported.

    Resolving the "Unable to display this Web Part" problem after SharePoint Designer restore

    SubmittedBy:  CI-tech1
    Description:




    If you've restored the SharePoint site using commands Site --> Administration --> Restore site and this site had special XSLT data views you may be in for a big surprise!
    You can receive the following message:
    Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.
    Or in Slovene language
    Spletnega gradnika ni mogoče prikazati. Če želite odpraviti težavo, odprite spletno stran v urejevalniku HTML, združljivim s storitvami Windows SharePoint Services, kot je program Microsoft Office SharePoint Designer. Če težave ne morete odpraviti, se obrnite na skrbnika spletnega strežnika.
    The problem is that while restoring the site, SharePoint designer doesn't correct the GUIDs of lists being used. For example: You're having an XSLT data view of a list called Contacts. When restoring SharePoint designer creates the list with a new GUID, but it uses the old GUID (from where the backup was made) of the list. The solution is simple: Fix the GUIDs of lists used in dataviews:
    1. Open the Manage content administration page of your site (http://server/site/_layouts/mcontent.aspx)
    2. Copy the shortcut of the list being used in XSLT to clipboard
    3. In the URL you'll find the new GUID of a list between brackets ( in http://server/site/_layouts/ListEdit.aspx?List={89D731E5-0538-4999-B4AF-D7A5D9EA781F} the GUID is 89D731E5-0538-4999-B4AF-D7A5D9EA781F
    4. With SharePoint Designer open the page with XSLT data view and search for term ListID in the code.
    5. Select the value of the ListID parameter. It should be the GUID of the list (either in ListID="....." or in the same tag, look for GUID-like numbers.
    6. Prest CTRL+H for Search and Replace with the value still selected. It will automatically populate the "Find what" field with it. Now paste the copied URL with GUID in the "Replace with" field and remove all but the GUID. Make sure you have the "Find in Source Code" option checked.
    7. Now just press the "Replace all" button and your XSLT data view will magically come to life :).
    I hope that this bug will be fixed with next version of SharePoint Designer, or maybe can develop some kind of plugin for that procedure to speed up the process for all the pages. I know that with FrontPage this wasn't happening.
    Technorati tags: sharePoint, backup, restore, SharePoint Designer, Data View, XSLT, GUID

    How to Activate the Drop Down Menu in MOSS Sites

    SubmittedBy:  CI-tech1
    Description:


    MOSS 2007 sites can display drop down menus in the tabbed navigation across the top.  Unfortunately there is not an easy check box to activate this functionality, instead things just have to be set up the right way.  If you want your MOSS site to show drop down menus, make sure the following is true or walk through the following steps:
    1. From the root of the parent site (Home) choose to create a new site (Site 1). Once that site is created, you will be in that new site. From here choose to create a new page.
    2. Once that is created, choose to create another new site (Sub Site 1).  Then create a new page in Sub Site 1.
    3. Your site structure should resemble this.
    4. For each site in the Navigation settings, both Show Subsites and Show Pages should be checked.
      • Select Site Actions - Site Settings - Modify Navigation.
      • Check Show subsites and Show pages in the first row.
    5. The end result would be a tab in the horizontal bar for Site 1, with a vertical drop showing Sub Site 1.
    The navigation shows sub sites under the parent and published pages at the parent. Pages for one site are stored flat in a single library.  If you want the navigation to show 2nd level sub site pages or 3rd level sub sites under the 2nd level, you need to make a very minor tweak to the master page that the site is using.
    1. Using SharePoint Designer (SPD), open the master page being used by the site.   Warning!  Making edits to this file will customize the file, a.k.a. unghost it.  Don't worry you can always undo this action.
      • In SPD, navigate to _catalogs/masterpage/*.master
      • How do you know which master the site is using? In the site, go to Site Actions - Site Settings - Modify All Settings, then choose Master page under the Look and Feel column.  Check which master page is selected in each drop down.
    2.  In the master page file, search for SharePoint:AspMenu.
      • You will more than likely have more than one instance of a menu control.  Look at the IDs to find the right navigation control for what you want to edit.  They are intelligently named, you will be able to sort out which one you need.   For default.master, look for ID="TopNavigationMenu".
    3. In the properties for the tag, find MaximumDynamicDisplayLevels="1".  Change the number from 1 to 2.
    4. Save the file and publish the master page (do this from SPD, Manage Content and Structure, or the Master Page Gallery).
    5. Refresh your browser.  Now when you mouse over Site 1 - Sub Site 1, you should see another level of navigation pop up.
    Cool, ehh?  Please don't abuse this dynamic display level.  As tempting as it is to provide instant access to something 5 levels deep in your site, drop down menus notoriously aggravate end users.  I highly recommend using no more than 2 levels (what we set in this walk through).
     

    1.Programming SharePoint Object Model, Web Services, and Events

    SubmittedBy:  CI-tech1
    Description:



    1. Programming SharePoint Object Model, Web Services, and Events

    2. Summary of .NET support

      • SharePoint will use ASP.NET instead of ISAPI for base page execution

      • Web Part Framework

      • Server Object Model for programmatic access to SharePoint data

      • We offer functionality as XML web services for access from remote machines

    3. .NET Object Model

      • Managed code object model on the server

      • Accessible via ASP.NET or any other server process

      • Implemented in C#

      • Exposes almost of all of the data stored in WSS

    4. NET Object model

      • Examples of what can be done with the Object Mode:

        • Add, edit, delete, and retrieve data from SharePoint Lists

        • Create new lists and set list metadata (e.g. the fields in a list)

        • Set web properties

        • Work with documents in document libraries.

        • Perform administrative tasks such as creating webs, adding users, creating roles, etc.

        • Pretty much any functionality in the UI can be automated through the OM!

    5. Example Objects

      • List Data

        • SPField

        • SPFieldCollection

        • SPListCollection

        • SPList

        • SPListItemCollection

        • SPListItem

        • SPView

      • Administration

        • SPGlobalAdmin

        • SPQuota

        • SPVirtualServer

      • Security

        • SPGroup

        • SPGroupCollection

        • SPSite

        • SPUser

        • SPUserCollection

      • Documents

        • SPDocumentLibrary

        • SPFile

        • SPFileCollection

        • SPFolder

    6. ASP.Net Security

      • For content stored in WSS, only registered set of web custom controls will run in pages

      • Inline script in the page will not execute

        • Code behind in pages can be made to work

      • All Executable code (e.g. web custom controls, web parts, and code-behind classes) needs to be installed on physical web server

    7. Getting Started with OM

      • Build a web part

        • This is the best option to write code that functions are part of a WSS site or solution

        • There will be lots of documentation with the beta on how to build a web part.

        • Web Part is reusable and can be managed using all of the web part tools and UI.

    8. Getting Started with the OM

      • Build an ASPX page

        • Code cannot live inline in a page within the site.

        • Creating pages underneath the /_layouts directory is often the best option for custom ASPX apps on top of SharePoint

          • This lets your page be accessible from any web. For example, if you build mypage.aspx in _Layouts, it is accessible from the following URLs:

            • http://myweb/_layouts/myapp/mypage.aspx

            • http://myweb/subweb1/_layouts/myapp/mypage.aspx

          • ASPX page will run using the context of the web under which it is running.

    9. Getting Started with the OM

      • Windows Executable or any other application

        • Object model can be called from pretty much any code context. It is not limited to just web parts or ASP.Net

        • For example, you could build a command-line utility to perform certain actions

    10. Demo

      • Hello World Web Part

    11. Working with the OM

      • The object model has three top-level objects:

        • SPWeb (represents an individual site)

        • SPSite (represents a site collection, which is a set of web sites)

        • SPGlobalAdmin (used for global administration settings)

      • In order to perform actions on data within a web, you must first get an SPWeb object.

    12. Adding our namespace

      • You should add references to the WSS namespaces to your source files

        • using Microsoft.SharePoint;

        • using Microsoft.SharePoint.WebControls;

        • using Microsoft.SharePoint.Administration;


    13. Key Object – SPWeb

      • Starting point to get at the Lists, Items, Documents, Users, Alerts, etc. for a web site.

      • Example Properties:

        • Web.Lists (returns a collection of lists)

        • Web.Title (returns the title of the site)

        • Web.Users (returns the users on the site)

      • In a web part or ASPX page, you can use the following line to get a SPWeb:

        • SPWeb myweb = SPControl.GetContextWeb(Context);

    14. Demo

      • Showing Web and List Properties

    15. Accessing data in a WSS List

      • Get a SPList or SPDocumentLibrary object.

        • SPList mylist = web.Lists[“Events”];

      • You can then call the .Items property to get all of the items:

        • SPListItemCollection items = mylist.Items;

      • If you only want a subset of the items, call the GetItems method and pass a SPQuery object

        • SPListItemCollection items = mylist.GetItems(query);

    16. Accessing data in a list

      • To get data for a field, specify the field name in the indexer for an SPListItem

        • foreach(SPListItem item in items)

        • {

        • Response.Write(item["Due Date"].ToString());

        • Response.Write(item["Status"].ToString());

        • Response.WRite(item["Title"].ToString());

        • }

    17. Full Example

      • SPWeb web = SPControl.GetContextWeb(Context);

      • SPList tasks = web.Lists["Tasks"];

      • SPListItemCollection items=tasks.Items;

      • foreach(SPListItem item in items)

      • {

      • output.Write(item["Title"].ToString() + item["Status"].ToString() + "
        ");

      • }

    18. Updating data

      • Most objects in WSS do not immediately update data when you change a property

      • You need to first call the Update() method on the object

        • This helps performance by minimizing SQL queries underneath the covers

      • Example:

        • SPList mylist = web.Lists[“Tasks”];

        • mylist.Title=“Tasks!!!”;

        • mylist.Description=“Description!!”;

        • Mylist.Update();

    19. Updating List Data

      • SPListItem is another example of an object where you need to call update:

      • Example:

        • SPListItem item = items[0];

        • item["Status"]="Not Started";

        • item["Title"]="Task Title";

        • item.Update();

    20. FormDigest Security

      • By default, the object model will not allow data updates if the form submitting the data does not contain the ‘FormDigest’ security key.

      • FormDigest is based on username and site. It will time out after 30 minutes.

      • Best solution is to include web folder control in ASPX page.

      • If you do not need the security the FormDigest provides, you can set to SPWeb.AllowUnsafeUpdates to bypass this check.

    21. Adding Users to a web

      • Get the appropriate SPRole object:

      • SPRole admins = web.Roles["Administrator"];

      • Call the AddUser method:

      • admins.AddUser("redmond\gfoltz","Greg@hotmail.com","Greg Foltz","");

    22. Demo

      • Adding users to the site via the OM

    23. Keep objects around

      • If you create and destroy objects frequently, you may do extra SQL queries and have code that is incorrect:

      • Bad Example:

        • SPWeb web = SPControl.GetContextWeb(Context);

        • web.Lists["Tasks"].Title="mytitle";

        • web.Lists["Tasks"].Description="mydescription";

        • web.Lists["Tasks"].Update();

      • Good Example:

        • SPWeb web = SPControl.GetContextWeb(Context);

        • SPList mylist = web.Lists["Tasks"];

        • mylist.Title="mytitle";

        • mylist.Description="mydescription";

        • mylist.Update();

      • SharePoint will have web services APIs for accessing content. The web services layer will be built on top of the server OM.

      • Allows manipulation of Lists, Webs, Views, List Items, etc.

      • Functionality will be similar to server object model, but with fewer interfaces optimized to minimize transactions.

      • Office11 (e.g. Excel, DataSheet, Work, Outlook, FrontPage, etc) use web services to access data from WSS.
      Web Services in WSS

    24. Web Service Methods

      • GetListCollection

      • GetListItems

      • GetWebCollection

      • UpdateList

      • UpdateListItems

      • GetWebInfo

      • GetWebPart

      • GetSmartPageDocument

      • And more…

    25. Getting Started With Web Services

      • Create a Windows Application

      • In Visual Studio, choose ‘Add Web Reference’

        • Enter http:///_vti_bin/lists.asmx to access the lists web service

        • Other services include:

          • UserGroups.asmx – users and groups

          • Webs.asmx – Web information

          • Views.asmx – View information

          • Subscription.asmx – Subscriptions

    26. Getting Started with Web Services

      • To send the logged on users’ credentials from the client, add the following line in the web reference object’s constructor:

        • public Lists() {

        • this.Url = "http://mikmort3/_vti_bin/lists.asmx";

        • this.Credentials=System.Net.CredentialCache.DefaultCredentials;

        • }

    27. Demo

      • Building a Web Service Client

    28. Events

      • We support events on document libraries.

        • Operations such as add, update, delete, check-in, check-out, etc.

        • Events are asynchronous

        • Events call IListEventSink managed interface.

      • Documentation and Sample in the SDK

    29. Optimizing Performance of OM

      • The biggest goal is to minimize the number of SQL queries.

        • It may be helpful to use the SQL profiler to monitor what the OM is doing underneath the covers

      • Minimizing managed/unmanaged transitions also a goal, though this is mostly taken care within the OM.

    30. What about CAML?

      • Page Execution will no longer be driven by CAML (XML schema used in SharePoint)

      • CAML is still used in several places

        • Field Type Definitions

        • Site and List Templates

        • View definitions

    31. SDK Available

      • Documentation about V2 available at http://msdn.microsoft.com/sharepoint/

    32. Questions?


    33. Code Example -- Enumerate Lists and Webs

      • private void ShowSubWebs(HtmlTextWriter output)

      • {

      • SPWeb web = SPControl.GetContextWeb(Context);

      • SPWebCollection mywebs = web.Webs;

      • foreach (SPWeb myweb in mywebs)

      • {

      • output.Write(myweb.Title + "
        ");

      • }

      • }

      • private void ShowSubWebsWithLists(HtmlTextWriter output)

      • {

      • SPWeb web = SPControl.GetContextWeb(Context);

      • SPWebCollection mywebs = web.Webs;

      • foreach (SPWeb myweb in mywebs)

      • {

      • output.Write("" + myweb.Title + "
        " + "
        ");

      • SPListCollection lists = myweb.Lists;

      • foreach (SPList list in lists)

      • {

      • if (list.ItemCount>10)

      • {

      • output.Write(list.Title + ": " + list.ItemCount + "
        ");

      • }

      • }

      • }

      • }

    34. Code Snippet – Copy Files

      • private SPWeb web;

      • private void Page_Load(object sender, System.EventArgs e)

      • {

      • web = SPControl.GetContextWeb(Context);

      • }

      • private void Button1_Click(object sender, System.EventArgs e)

      • {

      • int maxsize = Convert.ToInt32(TextBox1.Text);

      • SPFolder myfolder=web.GetFolder("Shared Documents");

      • SPFileCollection myfiles = myfolder.Files;

      • foreach (SPFile file in myfiles)

      • {

      • if (file.Length>(maxsize*1024))

      • {

      • Response.Write(file.Name + ": " + file.Length/1024 + "kb
        ");

      • file.CopyTo("Archive/"+file.Name,true);

      • }

      • }

      • }

    35. Code Snippet – Add users

      • private void Button1_Click(object sender, System.EventArgs e)

      • {

      • SPWeb web = SPControl.GetContextWeb(Context);

      • string username = TextBox1.Text;

      • string displayname = TextBox2.Text;

      • string email = TextBox3.Text;

      • SPRole admins = web.Roles["Administrator"];

      • try

      • {

      • admins.AddUser(username,email,displayname,"");

      • Label4.Text="Successfully added user";

      • }

      • catch(Exception ex)

      • {

      • Label4.Text=ex.ToString();

      • }
      • }