Tuesday, December 22, 2009
SharePoint 2010...What's Next? - Webcast Archive
FW: BA-Insight - SharePoint Search 2010 What's Next? - December 8th - Webcast recordning
Subject: BA-Insight - SharePoint Search 2010 What's Next? - December 8th - Webcast recordning
Monday, December 14, 2009
Start Workflow From c# Code
1: Guid wfBaseId = new Guid("{32601603-2149-447A-BD73-E64AF9307D6F}");
2: SPSite site = new SPSite(ConfigurationManager.AppSettings["SharepointSite"].ToString());
3: SPWeb web = site.OpenWeb(ConfigurationManager.AppSettings["SharepointWeb"].ToString());
4: SPList list = web.Lists["genericDocs"];
5: SPListItem item = list.Items[0]; 6: 7: 8: 9: 10: SPWorkflowAssociation associationTemplate= list.WorkflowAssociations.GetAssociationByBaseID(wfBaseId); 11: site.WorkflowManager.StartWorkflow(item, associationTemplate, "",true);
Windows Service That Starting Workflow by Code every X Time
1: 2: 3: 4: using System;
5: using System.Collections.Generic;
6: using System.ComponentModel;
7: using System.Data;
8: using System.Diagnostics;
9: using System.Linq;
10: using System.ServiceProcess;
11: using System.Text;
12: using System.Configuration;
13: using System.Threading;
14: using Microsoft.SharePoint;
15: using Microsoft.SharePoint.Workflow;
16: using System.Collections.Specialized;
17: namespace AlertWinService
18: {19: public partial class AlertWinService : ServiceBase
20: { 21: 22: #region Class Members
23: private bool m_bFirstLoop = true;
24: private string m_LogLevel = "";
25: public DataTable Mainresultdt = null;
26: SPListItem currentListitem = null;
27: System.Timers.Timer timer1 = new System.Timers.Timer();
28: #endregion
29: public AlertWinService()
30: { 31: InitializeComponent(); 32: } 33: 34: 35: private string querybuilder(StringCollection andClauses)
36: {37: StringBuilder sb = new StringBuilder();
38: sb = sb.Append("<Where>");
39: 40: //only 1 item
41: if (andClauses.Count == 1)
42: { 43: 44: sb = sb.Append(andClauses[0].ToString()); 45: 46: }47: //When the count is 2, we need to add one ‘And’ clause and add both item to be searched for
48: //two items
49: else if (andClauses.Count == 2)
50: {51: sb = sb.Append("<And>" + andClauses[0].ToString() + andClauses[1].ToString() + "</And>");
52: }53: //When the item count is greater than 2, we will add the ‘And’ clauses based on the count – 1.
54: else if (andClauses.Count > 2)
55: {56: for (int i = andClauses.Count - 1; i > 0; i--)
57: {58: sb = sb.Append("<And>");
59: }60: //After adding the proper number of clauses we will add the first two items and
61: //close the first ‘And’ clause off.
62: //Then, as we loop through the remaining items, we add another ‘And’ clause after each
63: //iteration and close then set.
64: // If you were to add ‘Or’ clauses, you could do the same.
65: sb = sb.Append(andClauses[0].ToString() + andClauses[1].ToString() + "</And>");
66: for (int j = 2; j < andClauses.Count; j++)
67: {68: sb = sb.Append(andClauses[j].ToString() + "</And>");
69: } 70: }71: //Finally we close the entire set off by adding the closing ‘Where’ clause.
72: 73: sb = sb.Append("</Where>");
74: 75: return sb.ToString();
76: } 77: 78: protected override void OnStart(string[] args)
79: {80: NetvisionLogger.WriteTolog("onstart");
81: SetTimerInfo(); 82: 83: 84: 85: 86: } 87: 88: private void SetTimerInfo()
89: {90: int iTimerIntervalMinutes = 60 * 24; // default is 24 hours interval
91: string sTimerIntervalMinutes = string.Empty;
92: 93: if (m_bFirstLoop)
94: {95: //m_LogLevel = ConfigurationManager.AppSettings["ExportLogLevel"].ToString().ToUpper();
96: sTimerIntervalMinutes = ConfigurationManager.AppSettings["ExportServiceStartDelayInMinutes"];
97: }98: else
99: {100: this.timer1.Stop();
101: sTimerIntervalMinutes = ConfigurationManager.AppSettings["ExportTimerIntervalMinutes"];
102: } 103: 104: // System.Diagnostics.EventLog.WriteEntry("Train_PublicApplicationsExport", "SetTimerInfo - setting timer interval to: " + sTimerIntervalMinutes, EventLogEntryType.Information, 888);
105: // to do Update the splist item
106: 107: 108: NetvisionLogger.WriteTolog("SetTimerInfo - setting timer interval to:" + sTimerIntervalMinutes + " Minutes");
109: if (!string.IsNullOrEmpty(sTimerIntervalMinutes))
110: { 111: iTimerIntervalMinutes = Convert.ToInt32(sTimerIntervalMinutes); 112: }113: this.timer1.Interval = (1000 * 60) * iTimerIntervalMinutes;
114: this.timer1.Enabled = true;
115: this.timer1.Elapsed+=new System.Timers.ElapsedEventHandler(timer1_Elapsed);
116: 117: this.timer1.Start();
118: 119: } 120: 121: void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
122: {123: NetvisionLogger.WriteTolog("Alert Windows Service WorkFlow Start");
124: 125: 126: 127: 128: // workflow based id
129: /*Guid wfBaseId = new Guid("{32601603-2149-447A-BD73-E64AF9307D6F}");
130: SPSite site = new SPSite(ConfigurationManager.AppSettings["SharepointSite"].ToString());
131: SPWeb web = site.OpenWeb(ConfigurationManager.AppSettings["SharepointWeb"].ToString());
132: SPList list = web.Lists["genericDocs"];
133: SPListItem item = list.Items[0];*/
134: /*site.AllowUnsafeUpdates = true;
135: item["Title"] = "Alert Windows Service";
136: item.Update();
137: site.AllowUnsafeUpdates = false;*/
138: 139: 140: 141: /*SPWorkflowAssociation associationTemplate= list.WorkflowAssociations.GetAssociationByBaseID(wfBaseId);
142: site.WorkflowManager.StartWorkflow(item, associationTemplate, "",true);*/
143: 144: SPSecurity.RunWithElevatedPrivileges(delegate()
145: { 146: UpdateSharepointDocumentLibrary(); 147: }); 148: 149: 150: } 151: 152: 153: private void UpdateSharepointDocumentLibrary()
154: { 155: 156: using (SPSite site = new SPSite(ConfigurationManager.AppSettings["SharepointSite"].ToString()))
157: { 158: 159: using (SPWeb web= site.OpenWeb(ConfigurationManager.AppSettings["SharepointWeb"].ToString()))
160: {161: //SPDocumentLibrary doclib= new SPDocumentLibrary();
162: SPFolder doclib = web.Folders[ConfigurationManager.AppSettings["SharepointDocLib"].ToString()];
163: StringCollection andClauses = new StringCollection();
164: 165: SPList list = web.Lists["genericDocs"];
166: // if therer is a keyword
167: andClauses.Add("<Contains><FieldRef Name='Title'/><Value Type='Text'>AlertWeb</Value></Contains>");
168: 169: 170: 171: 172: 173: 174: 175: SPQuery query = new SPQuery();
176: query.Query = querybuilder(andClauses); 177: 178: SPListItemCollection currentlistitemcoll = list.GetItems(query);179: foreach (SPListItem item in currentlistitemcoll)
180: { 181: currentListitem = item;182: break;
183: 184: }185: // resultdt
186: Mainresultdt = list.GetItems(query).GetDataTable();187: Random rr=new Random();
188: site.AllowUnsafeUpdates = true;
189: currentListitem["numberofworkflow"] = rr.Next();
190: currentListitem.Update();191: site.AllowUnsafeUpdates = false;
192: 193: } 194: } 195: } 196: 197: void timer1_Tick(object sender, EventArgs e)
198: { 199: 200: /*this.timer1.Stop();*/
201: NetvisionLogger.WriteTolog("Tick");
202: /*this.timer1.Start();*/
203: } 204: 205: 206: protected override void OnStop()
207: { 208: 209: timer1.Stop(); 210: } 211: } 212: } 213: SharePoint 2010 Developer Dashboard Visualizer
What it does
The Developer Dashboard feature of SharePoint 2010 is a kick-butt tool and something like an uber version of the page trace you can get from ASP.NET. It's geared for SharePoint so knows about SharePoint-y things as well as SQL calls to the content database and other cool stuff. However it is limited and doesn't offer a ton of customization other than what you get OOTB. This project kicks things up a notch and is like the developer equivalent of YSlow for Firebug by providing you with a visualization of the page load. This is great in finding bottlenecks and deciding where to start with your code optimization (or if you have some troublesome webpart).
How it works
It's jQuery man, and that's a good thing. Actually it doesn't do much other than re-present what the dashboard already contains however trying to decipher the call stack from numbers is for the birds. The visualization is nice and helpful in trying to wrap your head around what your web parts are doing. The package is cool as a WSP so deployment is a breeze. It just adds a new ASCX control to the AdditionalPageHead delegate control and spits out additional javascript tags. You'll need to turn the developer dashboard on to see the results but the install was simple and worked great.
Bottom line
This is just the beginning of hopefully a lot of add-on tools for developers. SharePoint 2010 offers a lot of great tools but sometimes their visibility is lost or hard to find. Tools like this are simple add-ons for your development environment and low hanging fruit to help you along. Even if you're not looking for code bottlenecks (who is?) it's nice to have this on the page so you *can* take a look and say "Hmmm, I should really look into that long call to load". I'm not saying let's install these tools and go nuts on pre-optimization, but knowing about something is half the battle. Install this on your VM and pull it out from time to time.
Project Site
Download
Sunday, December 13, 2009
sharepoint 2007 Migrating content
I have two boxes; web01 and web02 (Win2K3/MOSS 2007). Both boxes use an SQL box sql01 for their databases.
Web02 is going to be decommissioned, and required content needs to be migrated over to web01.
I am doing the easy stuff first like copying lists etc over as templates.
The tricky part is the document management system (DMS) that exists on web02. I need to copy the content including metadata to a new site on web01,
update the CT and metadata, and then decommission web02 and commission the new site on web01.

the best way to do this.
1. Backup the DMS website (on Web02) through SharePoint Designer (our DMS was a Document Center Website)
2. Create a empty site on Web01
3. Restore the backup on the newly created empty site on Web01, again using SharePoint Designer
It worked nice for me…hope it helps
Bug with the LookupField control when the number of items is greater than 20
If the number of items is <= 20 then the control generate a DropDownList. If the number of items is > 20 then the control generate a TextBox and an Image
When the LookupField has more than 20 items, we receive thew following error: Microsoft JScript runtime error: Object required The problem is raised in the Core.js file in the AbsLeft method.
function AbsLeft(obj)
{
var x=obj.offsetLeft;
var parent=obj.offsetParent;
while (parent.tagName !="BODY")
{
x+=parent.offsetLeft; parent=parent.offsetParent;
}
x+=parent.offsetLeft;
return x;
}
The error is on "while (parent.tagName !="BODY") ". It appears that the loop never finds the BODY tag in the HTML document. I read on the Internet that this situation can occurs when using relative and absolute positionning within the CSS.
The best way I have found to make sure a lookup field is rendered as a normal dropdown, rather than that quirky thing SharePoint likes to insert, is to change the bound control in the XSL from "SharePoint:FormField" to "SharePoint:DVDropDownList".
You then have to add an extra data source to populate the dropdown options, but I've found this to be usefull too, since you can sort and filter the items in the list.
This is more like the traditional dropdown binding scenario - get the list of options from the lookup table and populate the selected choice from the proper field in the "main" table. The wierdo thing here is that the DVDropDownList control doesn't look as if it is bound to the "main" table (or, in this case, List) because of the esoteric syntax of the ddwrt:DataBind method.
Solution Steps:
1. Add a new "SharePoint:SPDataSource" to the web part that points to the list containing the lookup items
2. Replace the "SharePoint:FormField" control with a "SharePoint:DVDropDownList" (I just leave the old control and overwrite the element)
3. Change the appropriate element attributes (see code attachment)
4. Update the ddwrt:DataBind call to pull input from the new DVDropDownList control
5. ! Note that in ddwrt, "i" is for insert and "u" is for update
I hope this helps, as I know this is a frustrating problem. It's a rather ridiculous work-around, but that's SharePoint for you...
Access denied error when adding new page to sharepoint
2) Go to Galleries ; Master pages and page layouts
3) From the list toolbar, select Settings ; Document library settings
4) Select permissions for this document library
5) Add 'Restricted Read' access to the required groups
Saturday, December 12, 2009
PDF Icon In Moss / Sharepoint 2007
moss ( Sharepoint 2007) doesn't install an icon for pdf document type file by default . inorder to
install the pdf icon into moss you should follow the following stips :
1) right click to download image
2) save the icon to (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\template\images) and rename the file to icpdf.gif
3) open the file docicon.xml you should find it here : C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\template\xml\docicon.xml
4) add a new mapping key

and now you can see the pdf icon for all the pdf documents within your portal .