Aug 3, 2009

Database Transactions in NetTier

Transactions are must when working on real time projects, always compliy with ACID properties

Try the following:

TransactionManager tran = DataRepository.Provider.CreateTransaction();
tran.BeginTransaction();
bool success = false;
try
{
// do some inserts / updates / etc
DataRepository.TicketProvider.Update(tran, ticket); //OR INSERT METHOD
UpdateSharePointLibrary(ticket.XML);
success = true;
}
Catch(Exception ex)
{
Success = false;
}
finally
{
if (success)
tran.Commit();
else
tran.Rollback();
}

If the above approach doesn't work try the one below:

try
{
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.MaxValue))
{
//web service call
// db calls
...
scope.Complete();
}//scope

}
catch (Exception ex)
{
.....
}

Jul 29, 2009

SharePoint WebService Response and XML Parsing

XML Parsing

XML Returned by WebService Call


XML Parsing

private bool IsGroupExisting(ugWebService.UserGroup ugws, ArrayList grps)
{
bool flag = false;
try
{
if (grps != null & grps.Count != 0)
{
for (int i = 0; i < grps.Count; i++)
{
//Find the groups in the SP Level and if any exists notify
System.Xml.XmlNode ndGroup = ugws.GetGroupCollectionFromWeb();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(ndGroup.InnerXml);
System.Xml.XmlElement root = doc.DocumentElement;
System.Xml.XmlNodeList lst = root.GetElementsByTagName("Group");

foreach (System.Xml.XmlNode n in lst)
{
string name = n.Attributes[1].Value;
EventLogHandler.AddApplicationEventLog("IsGroupExisting Name ..." + name);
if(name.Trim().Equals(grps[i].ToString().Trim()))
{
flag = true;
break;
}//if
}//for each
if (flag)
break;

}//for
}//if
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

Jul 22, 2009

SharePoint Deplyoment Jobs frozen or stuck

Timer Jobs Status Stuck ..

i.e. when you check in the Centrl Admin under Solution Management, all you see is ...deploying, retracting, ...

Create a batch file and execute the following before and after the solution deployment on each application and web server in the SharePoint farm:

Content of the batch file below:
stsadm.exe -o execadmsvcjobs
sleep 15
net stop SPTimerV3
sleep 5
net stop SPAdmin
sleep 5
net start SPTimerV3
sleep 5
net start SPAdmin
sleep 5
iisreset /noforce


NOTE: Can't find sleep command. Use the external sleep command you can search for Windows Server 2008 Resource Kit or Windows Server 2003 Resource Kit

May 5, 2008

SharePoint the Content Editor WebPart (Dark Horse)

Content Editor WebPart or CEWP provides us lot's of capability:

* Write HTML inside it

* Use javascript to do anything
   like
   - calling Sharepoint WebServices
   - create left treeview navigation

* Insert CSS inside the content page

* URL manipulation (i.e. URL Query String or Parameters)

* CSS for Infopath forms (like making tool tip size small) otherwise seems impossible
  
Snippet
"... Using a content editor web part you can insert the required Html (also CSS) into a page. Leveraging this technique we were able to add a content editor web part (CEWP) to our custom application page which hosts the infopath form. This content editor web part envelopes the CSS changes required to the tool tip...."

Now you are free to do anything using CEWP, CSS, HTML, Javascript, Javascript calling SharePoint WebServices and so on.

Apr 1, 2008

Writing SharePoint WebParts with Elevated Privilege and Custom Tool Part ( Hello World SharePoint WebPart )

Topic

Writing / Creating Sharepoint WebPart  with Elevated Privilege and Editor Part
( Hello World SharePoint WebPart )

Prerequisites
  • Microsoft Visual Studio 2005
  • SharePoint 2007 Farm
What is Elevated Privilege
Occasionally your code calls restricted methods within the Windows SharePoint Services(WSS/MOSS) object model.

This code will throw error, access denied in the event logs if not called properly. To make the code run even though the request is initiated by a nonprivileged user, you must be able to elevate the privilege of your code as it executes on the Web server. This blogs exactly shows you how to achieve this.

What is Editor Part
Basically the Properties of a Web Part.

These properties can be edited in the webpart page edit mode as shown below:


Tools used in the demo solution

*  VeWss for Visual Studio
     i.e. Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions, Version 1.1
    Download: link

* Deployment Tool
   Download link SharePoint Solution Installer


WebPart Development Steps

* Download the source code for the demo
* Open in VS 2005 and you will see a folder hierarchy as shown in the diagram
Files / Components involved

* WebPart Code
* Custom Editor Part
* Cab.ddf
* Manifest.xml
* Element.xml
* Feature.xml
* Mango.webpart
* Run "CreateSolutionPackage.cmd" (under package directory of source code)

























* Build the downloaded Project Solution File in VS 2005
* Drag and drop the assembly in the GAC

* Modify the web.config to add assembly as safe control
<

* Edit Setup.exe.config as/if required
SafeControl Assembly="Mango, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" Namespace="Mango" TypeName="*" Safe="True" />
* Use the setup.exe to install the solution

* To make sure everything work as expected, execute the following from command prompt
   stsadm -o execadmsvcjobs

* Activate WebPart, and then Add WebPart to the page.

Download Link source code

Enjoy Coding!

Pages