![]() |
SPSFAQ SharePoint Server Frequently Asked Questions |
|
Customising SharePoint
SPSFAQ0302105 - A clever way to develop web parts. - 0 Comments - stephencummins - Thu, Jun 3rd, 2004 - Customisation You may find it easier to use the STSADM.EXE utility to do all of this work for you. I set up a CAB project for each of my web part/control collections, and instruct it to include "primary output" and "content files" from my web part/control project. I then set the output directory to point directly to the root folder of my site on the web server, so taht whenever I recompile, the cab file is saved there.
When I am ready to update the web parts/controls on the server, I run a batch file that I create for each site. (see below) ************* SAMPLE BATCH FILE *********** @echo off c: cd c:\inetpub\wwwroot\emis "C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\Bin\StsAdm.exe" -o deletewppack -name EmisWebPartSetup.cab "C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\Bin\StsAdm.exe" -o addwppack -filename EmisWebPartSetup.cab -url http://envtst01:20080/ pause ************* I could have left out the line that does the deleting of the old web part package, and just added the "-force" option to the line that does the adding, but I like to see a result that it was successfully removed (if it exists) and added. Replace "EmisWebPartSetup.cab" with the name of your CAB file. If you only have one SharePoint site on your web server, or you want the package applied to all SharePoint sites simultaneously, then leave off the "-url http://envtst01:20080/" portion, otherwise, change it to specify your desired site(s) to install to. By using STSADM.EXE to do the install and removal, you don't have to mess with ANY of the files, and you don't have to perform an "iisreset" on the web server afterwards either. I hope this helps. Eric SPSFAQ0302104 - How do I start developing a SharePoint 2003 workflow? - 0 Comments - stephencummins - Mon, May 17th, 2004 - Customisation Not as hard as you think, you just need the basics, and I'll give them to you!
Essentially, you want code that can do this: • Move files based on property values set by the user • Change or set properties programmatically, such as a unique ID/Reference number. • Create new list items based on rules, for example "when the user changes the property "Reviewed" to "Yes", move the file to this folder, then add a list item somewhere else with the URL of the file. Step 1: Read the article in the link below and download the VB.NET project. It gives you the EventSink that listens to the standard SharePoint events: Checkin, Insert Update. It also writes a log of all Events to the Application Event Log. This could be changed to create an Audit log with a little work! This article also tells you how to enable events and call your code from the Document Library. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_SP2003_ta/html/sharepoint_wsseventing.asp Step 2: Incorporate the "Impersonating an Identity"code from the article in this link. It also gives a clearer path for how to enable Events, so take a look. "Impersonating an Identity" means specifying an account in your code that has the rights to move content or set properties. Otherwise, the user's own credentials are used and they are not enough. I use an admiistrator account and that works for me. http://www.microsoft.com/belux/nl/msdn/community/columns/tisseghem/infopathdeserialization.mspx Step 3: Add your Workflow rules. Here are some examples. Unique ID This is not a perfect solution, but it is workable. To programmatically fill in a Reference Number that is unique to this document Library use this code. It counts the number of milliseconds since 01/01/01, it then only shows the last 10 digits to stop it being too long. Problem: users could change this, I've no idea how to hide or make read-only a Document Library property. Under the line: Case SPListEventType.Insert Place this: oItem("Unique ID") = Right(System.DateTime.Now.Ticks.ToString(), 10) oItem.Update() Just make sure you've added a column to your Doc Lib called "Unique ID". Set the description to DO NOT CHANGE, to discourage tampering by users. If you move this document somewhere else, so long as the property "Unique ID" is there too, the value will move with the file. Move a file based on a user setting or changing a property value. Place this code in the Checkin, Update and Insert EventTypes to make sure you always catch this property being changed. If oItem("Move to") = "Some Library" Then SharePointEventItem.MoveTo(SharePointWeb.Url.ToString() + "/Document Library/" + SharePointEventItem.Name, True) End If The idea here is to perhaps use radio bottons or a dropdown to let users move the document through the workflow, Include a default that is blank so they don't have to move it! If oItem("Move to") = "" Then SharePointEventItem.MoveTo(SharePointWeb.Url.ToString() + "/The library it is in now/" + SharePointEventItem.Name, True) End If Creating a new List item with some of the property values copied over. You could use this to create a sort of task list or something. Add this in the Insert event. Dim listItems As SPListItemCollection = SharePointWeb.Lists("Some List").Items Dim item As SPListItem = listItems.Add() item("Unique ID") = oItem("Unique ID") item("Another Property") = oItem("Another Property") item("Path to the file") = SharePointWeb.Url.ToString() + "/" + SharePointEventItem.Url.ToString() item.Update() Add this in the Update event. It will check to see if an updated item (oItem) in the Document Library's ID matches an item (item) on the List, if so, it deletes the List item and replaces it with the new one. Some more sophisticated code that just keeps the two in Sync could be done too, but I'm just giving you the basics here. Dim listItems As SPListItemCollection = SharePointWeb.Lists("Administration").Items Dim itemCount As Integer = listItems.Count Dim k As Integer For k = 0 To itemCount - 1 Dim item As SPListItem = listItems(k) If oItem("Unique ID") = item("Unique ID") Then listItems.Delete(k) Dim newitem As SPListItem = listItems.Add() item("Unique ID") = oItem("Unique ID") item("Some Property on the List") = oItem("Some Property in the Document Library") item("Path to the file") = SharePointWeb.Url.ToString() + "/" + SharePointEventItem.Url.ToString() newitem.Update() End If Next k Writing to a list on a site that isn't the one where the event fired from Dim Site As New SPSite("http://sharepoint-server") Dim Web As SPWeb = Site.OpenWeb("/sites/Site-Name") Dim listItems2 As SPListItemCollection = Web.Lists("List-Name").Items ' These lines add a new item to the list. Dim item2 As SPListItem = listItems2.Add() item2("Unique ID") = oItem("Unique ID") item2("Some Property on the List") = oItem("Some Property in the Document Library") item2("Path to the file") = SharePointWeb.Url.ToString() + "/" + SharePointEventItem.Url.ToString() item2.Update() Other sites of use: Links to other Workflow solutions http://markharrison.europe.webmatrixhosting.net/posts/313.aspx A SharePoint 2003 Workflow project http://dotnetjunkies.com/WebLog/lamont_harrington/ MSDN Technical Articles: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_2003_ta/html/odc_landsppt03_ta.asp Handling Document Library Events: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spptsdk/html/tsptDocLibEvents.asp SharePoint 2003 workflow Part 2: Assigning a unique incrementing ID for all documents. By Stephen Cummins A few people have asked for a way to create a Unique Id for documents that simply increments from one so that the numbering is 1, 2, 3, 4, etc. So I've created some code for the insert event from the code of my previous article that does just that. How it works is one master list has a list item with a property that increments every time a new document is added to any document library on the server. This value is then assigned to the Unique ID property for that new document. Here is how it is done, first create this Master list to maintain the Unique ID. Create a new site, call it "Ref" or anything you want and create a new custom list,not a document library, in there called "Unique ID". To create a new list, just click "create" on the top menu, make sure you're logged on as the Administrator when you do this of course. Give the list a new column called Unique ID (by clicking "Modify Settings and Columns", then "New Column") make it the type "Number", set the value to 0 or 1, whatever suits. Now, add the following code, with a few modifications, to your Insert event. Comment out the line of code I gave you previously that sets the Unique ID. ' we don't need this line anymore so comment it out ' oItem("Unique ID") = Right(System.DateTime.Now.Ticks.ToString(), 10) ' Only needed in Insert command, this new code adds an incremented Unique ID to the new item from the Unique ID List Dim Site As New SPSite("http://your-server-name") Dim Web As SPWeb = Site.OpenWeb("/sites/your-ref-site-name") Dim listItems2 As SPListItemCollection = Web.Lists("Your Custom List Name").Items ' this line refers specifically to our Unique ID list item by the ID, make sure this is correct by adding the ID property to the default view on your custom list Dim newitem As SPListItem = listItems2.GetItemById(1) ' increment the value of Unique ID in the list newitem("Unique ID") = newitem("Unique ID") + 1 newitem.Update() ' We now set the value of the Unique ID on our document to the value of the Unique ID list item oItem("Unique ID") = newitem("Unique ID") oItem.Update() Note when you test this, you might have to hit refresh after you add a document to see if the value was assigned properly! SPSFAQ0302103 - How do I add a top level site template in SPS2003? - 0 Comments - stephencummins - Fri, Feb 13th, 2004 - Customisation Templates at portal level need to be added via
stsadm.exe (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\BIN) with this command: stsadm.exe -o addtemplate -filename c:\name.stp -title "Title" You should be able to log into sharepoint machine as administrator and then run stsadm -o enumtemplates and this should return list of template titles and their ID,membership. Then you can choose to delete any of those templates use stsadm -o deletetemplate -title "title of template" . SPSFAQ0302112 - Are there any Are there any test frameworks for Web Parts? - 0 Comments - stephencummins - Fri, Feb 13th, 2004 - Customisation http://aspunit.sourceforge.net
ASPUnit is for ASP pages. There is a unit testing framework that I use when writing Web Parts for .NET (all web parts must be written in .NET for the 2003 product). It's called NUnit and can be found here: http://sourceforge.net/projects/nunit Works great, you just have to deploy your NUnit assemblies to your SPS server (I put them in the GAC so I don't have to worry about them) Bil Simser SPSFAQ0301112 - Where is the _Layouts folder and all the other layout files? - 0 Comments - stephencummins - Fri, Feb 13th, 2004 - Customisation C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS
All the ASPX files are in the 1033 subdirectory. The images and CSS files are in there too, under images and styles. STSADM.exe is here: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\BIN SPSFAQ0301111 - Delete all for the subscriptions for a particular user. - 0 Comments - stephencummins - Mon, Oct 20th, 2003 - Customisation Michael Reinhart set me this script which is sure to be useful, enjoy!
‘ Start of script ' This code deletes all subscriptions for specified user on specified workspace ' Author: Michael Reinhart, 2003 Option Explicit Dim oSubMgr, strWorkspace, oResMgr Dim i, strXMLResults, ElemList, xmlDoc Dim strXML, strSubscriptionIDs, strUserID, oArgs, strOurDomain ' Change the next variable to your domain strOurDomain = "DOMAIN" strWorkspace = InputBox ("Enter the Workspace name (eg: PORTAL)","Workspace") strUserID = strOurDomain & "\" & InputBox ("Enter the UserID for subscription deletion (eg: jdoe)","UserID") If strWorkspace = "" Then WScript.Quit End If If strUserID = "" Then WScript.Quit End If Set oSubMgr =CreateObject("PKM.SubscriptionManager") Set oResMgr= oSubMgr.GetResultManager(strWorkspace) strXMLResults = oResMgr.GetResults(strUserID) Set xmlDoc = CreateObject("microsoft.xmldom") xmlDoc.async = False xmlDoc.loadXML(strXMLResults) Set ElemList = xmlDoc.getElementsByTagName("SubId") If ElemList.length > 0 Then For i=0 To (ElemList.length -1) strSubscriptionIDs = strSubscriptionIDs & ElemList.item(i).text & vbcrlf oSubMgr.DeleteSubscription strWorkspace, ElemList.item(i).text Next msgbox "Subscriptions:" & vbCRLF & strSubscriptionIDs & vbCRLF & _ "For user: " & strUserID & vbCRLF & "Deleted" Else MsgBox "There were no subscriptions found on " & strWorkSpace & _ " for user " & strUserID & "." End If set elemlist = nothing set xmldoc = nothing set oSubMgr = nothing Set oResMgr = nothing ‘ End of Script SPSFAQ0302110 - How do I create strong named Web Parts for SPS2003? - 0 Comments - stephencummins - Sat, Aug 9th, 2003 - Customisation These notes a bit rough, but they're what I used to create a working v2TR web part, I hope they help someone. Thanks to James Edelen for his help on this.
To create a strongly named Web Part, from a command line cd to: C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin Or wherever your .NET Framework SDK is installed, or just do a search for sn.exe and type in sn -k myKey.snk Later we'll copy this file to the Project folder, then install (addwppack) the web part cab file so that we can look in c:\inetpub\wwwroot\web.config and find the line: <SafeControl Assembly="YourWebPart and copy this part: Version=1.0.0.0, Culture=neutral, PublicKeyToken=123456789abcdefg To put in your DWP files You'll have to reBuild and readd this CAB file now. Visual Studio: File | New | Project... Visual C# Projects | Web Part Library Right-click Solution 'YourWebPart' in Solution Explorer Add| New Project... Setup and Deployment Projects | Cab Project In Solution Explorer, right-click Cab and Add | Project Output... Choose Primary output and Content Files In Solution Explorer, open Manifest.xml and delete: <ClassResources> <ClassResource FileName=""/> </ClassResources> Open WebPart1.cs and add: using Microsoft.SharePoint.WebControls; Find the line: output.Write(SPEncode.HtmlEncode(Text)); And substitute your code, there are examples in the SDK Open webPart1.dwp and add the following inside the assembly tag: YourWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=123456789abcdefg Open Assemblyinfo.cs Change [assembly: AssemblyKeyFile("")] to [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] Add the file mykey.snk to the Project folder, in Visual studio projects/YourWebPart Build | Build Solution Command Line cd to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\BIN Type in stsadm -o addwppack -filename "C:\Path\to\cab.cab" -globalinstall -force Globalinstall puts it in the GAC and force overwrites the CAB if it is already there If you have to redo this step, you have to type IISRESET To add the Web Part: Modify Shared Page | Add Web Parts | Browse | Virtual Server Gallery Drag and drop. To delete a web part after it has been dragged, not just close it, you have to select Modify Shared Page | Design this page then on the Web Parts dropdown select delete. To delete a web part CAB, you can see them all with stsadm -o enumwppacks to delete type: stsadm -o deletewppack -name yourwebpart.cab Stephen SPSFAQ0301109 - How do I make the Search web part scope 'this folder' search subfolders too? - 0 Comments - stephencummins - Thu, May 1st, 2003 - Customisation You have to change Portal/resources/searchFunctions.js
Replace strTahoeScopeConstraint = getValueFromFormField( g_strSearchFormId, g_strSearchScopeClauseId ); with strTahoeScopeConstraint = ""; Page 10 of 24 - Jump to: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
|||||||||||||||||||||||||||||||||||||||||||||||||