Showing posts with label sharepoint tips. Show all posts
Showing posts with label sharepoint tips. Show all posts

Wednesday, 12 September 2007

Sharepoint Development Tips 6 - Developing Visual Studio Workflow for MOSS

pitfall 1:

there's a good article (well, for starters ) on msdn you guys can read to start your very first workflow using Visual Studio. But after firing up VS 2005 and ready to go with the instructions of this article, you found there's no onworkflowactivated1 as your necessary starter of the dish... so basically that's how the init data will kick in from MOSS and your workflow won't work without it. Even if you add those 3 missing references already and are able to see the chart , it will be the same.

Solution: Don't trying to be clever, install ECM kit on your development server with sharepoint on, copy around the dll files needed by your project is not good enough this time.

pitfall 2:

The snippet is essential to have when completing your workflow.xml and feature.xml in order to install your workflow and all related Infopath forms. Rather than google on the Internet, as we know, MS provides this snippet coming with the ECM kit. But when you press ^K+X, the WSS snippet described in MSDN is not there.

Solution:
Serge Luka's blog did save us a lot of time to tell us where this snippet is. Simply press ^K+B to navigate to the path of "C:\Program Files\Microsoft Visual Studio 8\Xml\1033\Snippets\Windows SharePoint Services Workflow" and add the snippet code into your code snippet manager. There should be another one for MOSS but the workflow.xml and feature.xml should be the same.

pitfall 3

SendEmail activity always seems tempting when developing workflows using Visual Studio because email can be a very important process. While a lot of people complaining the activity does not do what it is supposed to even though there's no error in event viewer of Windows or ULS log of MOSS. Can it be security issues or central admin's outgoing email settings, etc... confusing

Solution:
Wake up, the MailMessage utility in System.net still works as well as in .net 2. If you know the smtp server's address , this can be perfect to use in this scenario. Anyway, even if SendEmail Activity works, you still have to specify the to, from, and body so on to make it send emails you want. MailMessage object that can be sent by SmtpClient is easier to handle. Just drag a code activity instead and put your SmtpClient+MailMessage inside the handler of that code activity. It's guaranteed working if you get your smtp outbound server's address.

Tuesday, 14 August 2007

Sharepoint Administration Tips 1 - Pitfalls in Moving Sharepoint DB

At some point we have to move database for sharepoint configuration either because the DB file / log is on system drive or the fast expanding of your sharpeoint DB log. If DB is full, you can still view the website hosted by sharepoint, but a lot of functions will stop working.

First thing first, do a full backup or differential backup if you have a full backup before. After that, to move the database, please read the relevant links in here;To move the database to another server, read here.

Note below:
After you have done the moving, you might run into problems like search settings changed , timer services stopped working correctly. For Search settings, we need to make sure the indexer is assigned to the SSP since moving the sharepoint will remove this. If you have enabled incoming email services for your sharepoint lists. It will stop working because the relationship between web app and sharepoint timer called Windows Sharepoint Incoming Email Timer is broken. To restore this, Go to Operation->Incoming Email Config->Select No on "
Enable sites on this server to receive e-mail? "->click ok and then come back to click "yes". After this, make sure to disable and re-enable the Application Server Administration Service Timer Job " and " Application Server Timer Job "this should fix the problem on incoming email.

Thursday, 5 July 2007

Sharepoint Development Tips 4- SPD workflow madness

As I introduced SPD workflow in my previous post,if all you need is simply customized activity and it's supposed to be stand-alone, i.e. doesn't need to be reused to another list in sharepoint, and you certainly don't want the hassle with init,complete forms with InfoPath, customized activity/condition with SPD's workflow designer is almost perfect choice. But when any offer looks too good to be true, it probably just is. Like the line in Supernatural, "This world just ain't coming without perks...", well, in the bad way in our case of course !-_-...

The catch is when you want to update your code using SPD, you will find the change you made will not be used by sharepoint. And as you come this far with it already, you know there's NO debugging support with SPD workflow. You really want to make sure it "somehow" just works anyway before you deploy it to the server. So how on earth we can make our updated dll work with the SPD workflow on the server? Well, you will have to live with the fact that you can't debug given the fact your dll will not contain huge amount of code. But to update the dll on the server, do the following.

1. Remove the workflow from your list in sharepoint
2. Shut down your SPD
3. Go to your website cache, on my XP pro the path for this is : "C:\Documents and Settings\%user%\Local Settings\Application Data\Microsoft\WebsiteCache", in vista , it's under different path:%System Drive%\Users\%user%AppData\Local\Microsoft\WebSiteCache(You will find it's a mistake to use Vista for professional development for now anyway). Delete everything you see there.
4. Copy the updated dll to the GAC on your server
5. IISRESET on your server
6. reopen SPD
7. Redeploy your workflow.


In this way, you will update your SPD workflow with latest dll. But I have run into the occasions that even above method will not update your dll. I ended up restarting the sharepoint server to get it updated(too much for a real-world software solution , is it?). Hopefully this will help you.

Update:
now every time I have to restart the sharepoint server to make changes. :(

Sharepoint Development Tips 3- Dealing with SPUser- the slippery object

Most of the time you will want to obtain the SPUser object from your sharepoint list. One thing that will defintely make you wonder is how you cast the listitem column containing user info to the SPUser object. If you go


SPUser thisUser = (SPUser)thisItem["User_Column"];




VS will not let you compile because the underlying type of your "User_Column" is just a string, so the cast will fail. So what you can do is to search & compare the user collection in your web site, and get the SPUser from the compared result like following:


private SPUser GetOwnerFromString(string _userString, SPWeb thisWeb)
{
//parse the string after the delimiter '#'
int delimIndex = _userString.IndexOf("#");
string userStr = _userString.Substring(delimIndex + 1);
SPUser owner = null;
foreach (SPUser thisUser in thisWeb.Users)
{
//if this is current user
if (thisUser.Name.ToLower().IndexOf(userStr.ToLower()) > -1)
{
owner = thisUser;
break;
}
}
return owner;
}


As you might have noticed, the delimiter to read the string is set to "#", that's because when you try to get the string from a column containing the user information, the string format will be scrambled up like "10283744#System Account". So the format is a random number + "#" + your user's display name.


This method will work if you populate the user list of sharepoint by users rather than by AD groups. I didn't try the AD group case but will do later.

Thursday, 21 June 2007

Sharepoint Development Tips 2-CAML Power!

CAML(Collaborative Application Markup Language) is the tool you want to use before you mess around with querying your sharepoint list and views with foreach(s). Experience prooved that foreach the whole list or in case you have to use embedded foreach statement, the performance is quite disappointing. The alternative is to use CAML which is used by sharepoint by default when creating views for lists.

The usage is easy. It's like the NHibernate's HQL if you use it before.
In here, I have a list called "Team List". Now I want to obtain the item that has the Job No.(job number)of 12 and Customer Name(customer's name )is equal to "Your Name", the CAML statement will be like following


the syntax is relatively easy apart from one wicked requirement, the ASCII characters are needed to be encoded to hexidecimal value and with both prefix and suffix of '_', in our case the space character is encoded as x0020, and the '.' as x002e.

So the usage of above CAML will be by putting the CAML statement into a string e.g. teamQueryString:



SPQuery query = new SPQuery();
SPListItem resultItem =null;
query.Query= teamQueryString;

//in our case the result is unique
resultItem = teamList.GetItems(query);

By this way , you get the team with job number is 12 and customer name is "Your Name"

If you wonder how you could figure out what hex value to encode all the characters out there or you are too lazy to write the CAML at all, I recommend using U2U's CAMLBuilder, they are pretty handy and most importantly, it's free! (You can tell that I am that lazy by sensing the tone :P )

Tuesday, 19 June 2007

Sharepoint Development Tips 1-Workflow status code

When you want to retrieve the value of your sharepoint inbuilt workflow and use it somewhere else, say Infopath client/browser forms, the result of getting the string value of them are not like what you see in the web page as "in progress","Rejected",etc, it's all integer status code representing different status. So this is what I found out until now.

In Progress: 2
Approved: 16
Rejected: 17
Canceled: 4