in

Melyssa’s Blog

September 2008 - Posts

  • Event ID 10016 on a SharePoint Server

    After a new installation or an upgrade on a MOSS server, you may start receiving a million DCOM errors in your System event logs. Thankfully, these are very easy to clean out. The error will look something like this:

    The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID {<GUID>} to the user <server>\<service account> SID (S-1-5-21-<service account ID>).  This security permission can be modified using the Component Services administrative tool.

    For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

    1. Highlight and copy the GUID in the error description.
    2. Start > Run > regedit
    3. Click on the root node: My Computer
    4. Edit > Find… and paste the GUID into the textbox. Click Find Next.
    5. The right-hand pane should populate with the service information. Make note of the name in the Data field.
    6. Start > Administrative Tools > Component Services.
    7. Expand Component Services > Computers > My Computer > DCOM Config.
    8. Scroll down until you find the service name. Right click > Properties.
    9. On the Security tab, under Launch and Activation Permissions, make sure Customize is selected.
    10. Click the Edit button.
    11. Add the service account that was mentioned in the error description and give it Local Launch and Local Activation. (Some instances may need the remote launch/activation permissions as well.)
    12. Apply the changes and do an IISRESET.
    Posted Sep 25 2008, 11:29 AM by mbell with 1 comment(s)
    Filed under:
  • How to create and deploy a custom Web Part

    1.  Open Visual Studio 2005 and create a new Web Part project.

    2.  Add the following two using statements to the .cs file:

     

    using System.ComponentModel;

    using System.Net;

     

    3.  Add the following using statement to the AssemblyInfo.cs file:

     

    using System.Security;

     

    4.  Add the following line at the end of the AssemblyInfo.cs file:

     

    [assembly: AllowPartiallyTrustedCallers()]

     

    5.  Your Web Part should include a pre-assigned Guid.  Add the ToolboxData and XmlRoot Namespace after the Guid and remember to replace ‘YourClassName’ where appropriate, like so:

     

    [Guid("3854adbc-d5ac-47bd-885a-af46cc0f35d5"),

      ToolboxData("<{0}:YourClassName runat=server></{0}:YourClassName>"),

       XmlRoot(Namespace = "YourClassName")]

     

    6.  Your Web Part class should be inheriting from the System.Web.UI.WebControls.WebParts.WebPart class.

    7.  Add your code to the Render method, et al.

    8.  In Solution Explorer, rename the folder that is automatically created and named YourClassName to Solution and move the .cs file up one out of the Solution folder.

    9.  Add a manifest.xml file to the solution folder and place the following inside (remember to replace the instances of solution and class names, the solution id, and public key token with your own):

     

    <Solution xmlns=”http://schemas.microsoft.com/sharepoint/SolutionId=”ef5784a3-4970-459c-9397-57a95496f002“>

                <Assemblies>

                            <Assembly Location=”YourSolutionName.dllDeploymentTarget=”WebApplication“>

                                        <SafeControls>

                                                    <SafeControl                                                   Assembly=”YourSolutionName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5Namespace=”YourNamespaceTypeName=”*Safe=”True” />

                                        </SafeControls>

                            </Assembly>

                </Assemblies>

                <DwpFiles>

                            <DwpFile Location=”YourClassName.webpart“/>

                </DwpFiles>

                <CodeAccessSecurity>

                            <PolicyItem>

                                        <PermissionSet class=”NamedPermissionSetversion=”1Description=”Permission set for YourNamespace“>

                                                    <IPermission class=”AspNetHostingPermissionversion=”1Level=”Minimal” />

                                                    <IPermission class=”SecurityPermissionversion=”1Flags=”Execution” />

                                                    <IPermission class=”Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429cversion=”1ObjectModel=”True” />

                                        </PermissionSet>

                                        <Assemblies>

                                                    <Assembly Name=”YourSolutionName“/>

                                        </Assemblies>

                            </PolicyItem>

                </CodeAccessSecurity>

    </Solution>

     

    10.Right-click on your project file and open the properties. Click on the SharePoint Solution tab to get your solution id. Copy and paste the solution id into the manifest.xml file, top line, SolutionId attribute.

    11.Add another .xml file called YourClassName.webpart to your Solution folder (be sure to change the .xml extension to .webpart), and place the following inside:

     

    <webParts>

                <webPart xmlns=”http://schemas.microsoft.com/WebPart/v3“>

                            <metaData>

                                        <type name=”YourNamespace.YourClassName,

                                                    YourSolutionName,

                                                    Version=1.0.0.0,

                                                    Culture=neutral,

                                                    PublicKeyToken=9f4da00116c38ec5” />

                                        <importErrorMessage>

                                                    YourSolutionName Cannot import YourWebPartName Web Part.

                                        </importErrorMessage>

                            </metaData>

                            <data>

                                        <properties>

                                                    <property name=”Titletype=”string“>A title for your Web Part</property>

                                                    <property name=”Descriptiontype=”string“>A description for your Web Part</property>

                                                    <property name=”AllowClosetype=”bool“>FALSE</property>

                                        </properties>

                            </data>

                </webPart>

    </webParts>

     

    12.Add a text file called WSP.ddf to your Solution folder (be sure to change the .txt extension to .ddf), and place the following inside:

    .Set CabinetNameTemplate=YourSolutionName.wsp ;Specifies the name of the output file
    .Set DiskDirectoryTemplate=CDROM ;Indicates that all of the CAB goes into a single directory
    .Set CompressionType=MSZIP ;Indicates that all of the files will be compressed into CAB files
    .Set UniqueFiles=”ON” ;Indicates that all of the files referenced must be unique
    .Set Cabinet=On ;Use cabinet files
    .Set DiskDirectory1=. ;Use the current directory for the output CAB file

    “C:\…Your Path…\Solution\manifest.xml”
    “C:\ …Your Path…\bin\release\YourClassName.dll”
    “C:\…Your Path…\Solution\YourClassName.webpart”

     

    13.Compile the solution.

    14.Create the cab file: From the directory in which you want the cab file saved, run the following command:

     

    makecab /f “C:\…path to .ddf file…\WSP.ddf”

     

    15.Open a command prompt from the server on which the Web Part is to be installed and change directory to the 12 hive bin directory:

     

    cd “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\”

     

    16.Run the following commands:

     

    stsadm –o addsolution –filename “C:\…path to your file…\YourSolutionName.wsp”

     

    stsadm –o deploysolution –name YourSolutionName.wsp –url [http://YourServerName OR –allcontenturls] –immediate –allowcaspolicies –force 

    17.Your .dll should be in the bin directory of the Web App you specified in the deploysolution command (or in all bin directories of all Web Apps if you used the –allcontenturls switch). It should NOT be in the GAC.

    18.Visit the Solution Management page in Central Admin under the Operations tab. Your solution should be listed with a status of Deployed.

    19.Visit one of your Front-end Web Servers to which the solution was deployed. Edit a page and click to add a Web Part to the page. Scroll down to the Miscellaneous category and you should fine your Web Part there.

  • Exception from HRESULT: 0×80041050 Error on SharePoint Site with ForeFront

    There are several posts on this out there already, but I thought I’d add mine as well, just to have it down. If you have ForeFront managing your virus scanning for your SharePoint environment, then you may at some point receive some close resemblance of the following error when you navigate to your site:

    Exception from HRESULT: 0×80041050

    (I’ve also seen this error ending in a 4).

    #1: This is a known bug with ForeFront mistakenly flagging SharePoint pages as a virus, and Microsoft does have a hotfix for this issue (see KB943221; however in my case, the issue resurfaced several months after applying the hotfix).

    #2: To quickly get your site back up, (then worry about applying the hotfix), run the following query on each content database:

    select * from AllDocs where (VirusStatus > 0) and (VirusStatus is not null)

     If anything is returned, AND you are sure these files do not in fact contain a virus, then run the following query:

    update AllDocs set VirusStatus = null where (VirusStatus > 0) and (VirusStatus is not null)

     

    Your site should be back up in a jiffy. Also note that you will likely not find any events logged in ForeFront regarding these virus flags.

  • How to add a custom user control to a SharePoint page

    One way to get “home grown” .Net development in a SharePoint site is to use custom user controls (.ascx). Following are the general steps involved with making user controls function on a SharePoint site:
     

    1. Start a new Web Site in Visual Studio.

    2. Add a new user control page to the project - you may either include the code inline or as code-behind.

    3. Create the user control and place all code between the script tags on the page (inline) or in the code-behind file.

    4. For inline code, references to other assemblies should be placed outside the script tags and take the format:

    • <%@ Import Namespace=”System” %>

    5. Custom assemblies (class libraries, etc.) should be placed in the bin directory of the Web application hosting the user control.

    6. Save/compile the .ascx file (and .cs file if code-behind), then copy and paste it/them into the following location: C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/CONTROLTEMPLATES/

    7. Create a new folder in the features directory and give it the same name as your user control: C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES/

    8. Create two new files inside this new folder. Name one feature.xml and the other elements.xml.

    9. Open feature.xml for editing. Add the following xml to the file (replace the red bold text with the user control information):

    • <?xml version=”1.0″ encoding=”utf-8″ ?>
      <Feature Id=”5DD8CC0A-0EF5-4c14-8052-573E14021D7A
        Title=”User Control Title
        Description=”User control description.
        Version=”1.0.0.0″
        Scope=”WebApplication“  xmlns=”http://schemas.microsoft.com/sharepoint/“>
        <ElementManifests>
          <ElementManifest Location=”elements.xml” />
        </ElementManifests>
      </Feature>

    10. Open elements.xml for editing. Add the following xml to the file (replace the red bold text with the user control information):

    • <?xml version=”1.0″ encoding=”utf-8″ ?>
      <Elements xmlns=”http://schemas.microsoft.com/sharepoint/“>
        <Control
          Id=”aUniqueId
          Sequence=”100″ ControlSrc=”~/_controltemplates/Filename.ascx”>
        </Control>
      </Elements>

    11. Install the feature. Run the following command from the console (you must be in the “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\” directory first; replace the red bold text with the user control information):

    • stsadm -o installfeature -filename FolderName\feature.xml

    12. Activate the feature. Run the following command from the console (you must be in the “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\” directory first; replace the red bold text with the user control and scope information):

    • stsadm -o activatefeature -filename FolderName\feature.xml -url http://servername

    13. Start SharePoint Designer. Open your Web site and the page on which you want to add the user control.

    14. Add the following line of code to the PlaceHolderMain content place holder (replace the red bold text with the user control information):

    • <SharePoint:DelegateControl runat=”server” ControlId=”theUniqueId“></SharePoint:DelegateControl>

    15. Save the file and open in browser.

    Posted Sep 18 2008, 05:58 PM by mbell with no comments
    Filed under:
  • Security Trimmed Controls in SharePoint

    Let’s say you have a control on your page that you want only a certain group of users to see. Fortunately, SharePoint has a built-in control that lets you hide controls to which users do not have the necessary permissions.  This control is the SPSecurityTrimmedControl.
    <Sharepoint:SPSecurityTrimmedControl runat=”server” Permissions=”ManageLists”>
    Place your control(s) here
    </SharePoint:SPSecurityTrimmedControl>
    All you have to do is wrap your control with this security control and set the correct permissions in the Permissions attribute. The Permissions attribute, when used in Visual Studio or Designer, will have intellisense and will be filled with the following properties obtained from http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx.  Whatever permissions you specify will be required by the user in order to view the control(s) inside of the SPSecurityTrimmedControl:

    AddAndCustomizePages
    AddDelPrivateWebParts
    AddListItems
    ApplyStyleSheets
    ApplyThemeAndBorder
    ApproveItems
    BrowseDirectories
    BrowseUserInfo
    CancelCheckout
    CreateAlerts
    CreateGroups
    CreateSSCSite
    DeleteListItems
    DeleteVersions
    EditListItems
    EditMyUserInfo
    EmptyMask
    EnumeratePermissions
    FullMask
    ManageAlerts
    ManageLists
    ManagePermissions
    ManagePersonalViews
    ManageSubwebs
    ManageWeb
    Open
    OpenItems
    UpdatePersonalWebParts
    UseClientIntegration
    UseRemoteAPIs
    ViewFormPages
    ViewListItems
    ViewPages
    ViewUsageData
    ViewVersions

    ** You can also use the PermissionsString property to use a comma seperated list.
    Posted Sep 18 2008, 05:52 PM by mbell with 2 comment(s)
    Filed under:
Powered by Community Server (Commercial Edition), by Telligent Systems