Wednesday, June 10, 2009

Error in accessing Web Service in VSTA code of Infopath Form

When I am trying to access the web serice method in the VSTA code of Infopath form, I was getting the following error message:

The error message is “There is an error in XML document (1, 302)."

The stack trace is “ at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)

at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)

at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

at EmpSepChkLst.AD_SEARCH.NDAWebService.SerachUserInDomain(String UserName)

at EmpSepChkLst.CommonFunctions.GetUserInfo(String CurrentUserId)”.


The solution for this is:

You need to publish the infopath form with full permission( Tools -> Form Options -> Security and Trust -> Select Full trust). I was publishing with "Domain" permissions and it was throwing the error while opening the infopath form from Sharepoint Document Library.

Error while submitting Infopath form to a SharePoint Document Library

I was getting the following error when submitting the Info path Form to a SharePoint Document library:
"An exception of type 'System.Net.WebException' occurred in Microsoft.Office.InfoPath.Server.dll but was not handled in user code

Additional information: A value in the form may be used to specify the file name. If you know the value in the form that specifies the file name, revise it and try again. Otherwise, contact the author of the form template."


You need to make the changes in the share point submit data connection. The following steps will walk you through

1. Open form in Design Form
2. Go to Tools in menu bar
3. Select data connection
4. Select the Dta connection name that you had used to submit the form to Share Point
5. Click on 'Modify' button
6. Check 'Allow overwrites if file exists' check box
7. click on 'Next' button
8. Click on 'Finish' button
9. Click on 'Close' button
10. Save the form and republish the form to Your form Library

Monday, June 08, 2009

Useful SharePoint Links

Packaging and Deploying Features in SharePoint
http://msdn.microsoft.com/en-us/magazine/cc163428.aspx

WSPBuilder
http://wspbuilder.codeplex.com/

Developer Getting Started Guide
Introduction to SharePoint Products and Technologies for the Professional .NET Developer
http://msdn.microsoft.com/en-us/library/cc537498.aspx#MOSSIntroToNet_BuildingSharePointSolutionsUsingVisualStudio2008


Windows SharePoint Services (WSS) Developer Center
http://msdn.microsoft.com/en-us/sharepoint/default.aspx

Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 1 of 2)
http://msdn.microsoft.com/en-us/library/bb530302.aspx

Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 2 of 2)
http://msdn.microsoft.com/en-us/library/bb530301.aspx

SharePoint Products and Technologies Customization Best Practices
http://msdn.microsoft.com/en-us/library/bb861954.aspx

Windows SharePoint Services 3.0 SDK
http://msdn.microsoft.com/en-us/library/ms441339.aspx


Microsoft Office SharePoint Server 2007 SDK
http://msdn.microsoft.com/en-us/library/ms550992.aspx

Team-Based Development in Microsoft Office SharePoint Server 2007
http://msdn.microsoft.com/en-us/library/bb428899.aspx

Permissions for Running Customer Applications Against SharePoint
1. Grant rights to Remote Desktop onto Central Admin server
2. Add to Farm Admin group
3. Add to Site Collection Admin on Desired Site
4. Ensure DBO Access on Content DB of Desired Site
5. Add to Site Collection Admin on Central Admin
6. Ensure DBO Access on Central Admin Content DB
7. Add to Site Collection Admin on SSP
8. Ensure DBO Access on SSP Content DB
Using Server Side Data Connections in Forms
http://office.microsoft.com/en-us/infopath/HA100929071033.aspx?pid=CH100598301033

http://blogs.msdn.com/infopath/archive/2007/03/21/infopath-data-connections-part-1.aspx

Using CAML and Data Fields References
http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrieving-list-items-

http://weblogs.asp.net/gunnarpeipman/archive/2008/10/29/sharepoint-for-developers-3-3-hands-on-querying-lists.aspx

Using Profile Data Through a MOSS Web Service
http://blogs.msdn.com/infopath/archive/2007/03/07/get-the-user-profile-through-moss-web-services.aspx

SharePoint Explorer & SWAT Links
http://blog.mondosoft.com/ontolica/archive/2007/02/15/SharePoint-Explorer-for-WSS3.aspx

http://www.idevfactory.com/products/swat/

Running with Elevated Privileges

http://msdn.microsoft.com/en-us/library/aa543467.aspx

http://geekswithblogs.net/DanielC/archive/2008/01/28/sharepoint-security-runwithelevatedprivileges.aspx

Workflows with Windows Workflow Foundation and InfoPath

http://weblog.vb-tech.com/nick/archive/2007/02/25/2207.aspx

Worflow HowTwo’s from the SDK
http://msdn.microsoft.com/en-us/library/ms497003.aspx

Wednesday, December 17, 2008

To display the proper error messages in the SharePoint Site

1. On the Web server, navigate to the site directory:Local Drive:\Inetpub\wwwroot\wss\VirtualDirectories\[directory for site] (for example 84)
2. Open Web.config in Notepad.
3. Search for "CallStack". Change the CallStack status to "true".
4. Search for "CustomErrors". Change the mode to "off".
5. Save and close the file.

Thursday, November 20, 2008

Stock Ticker Web Part in SharePoint 2007 using web service

Requirement: To display our company stock quote details on a SharePoint HomePage

Solution:

Two ways:

1) Create web part to display the stock details in a Table,

i) Using rss feed url

ii) Using Web Service.

The sample code using Web Service is as follows:


StockQuote.StockQuote stkquote = new StockQuote.StockQuote();
string quote = stkquote.GetQuote("MCHP");//MCHP is the symbol for Microchip stock
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(quote);
XmlNodeList nodelist = xmldoc.GetElementsByTagName("Stock");
XmlNode xmlnode = nodelist[0];
string symbol = "", last = "", date, time, change = "", open, high, low, volume = "", mktcap, prevclose, percentgechange = "", annrange, earns, pe, name;
for (int i = 0; i < xmlnode.ChildNodes.Count; i++)
{
XmlNode node = xmlnode.ChildNodes[i];
if (node.Name == "Symbol")
symbol = node.InnerText;
if (node.Name == "Last")
last = node.InnerText;
if (node.Name == "Volume")
volume = node.InnerText;
if (node.Name == "Change")
change = node.InnerText;
if (node.Name == "PercentageChange")
percentgechange = node.InnerText;
}
tblStockTicker = new Table();
TableRow trStockTicker = new TableRow();
TableCell tcStockQuote = new TableCell();
HyperLink hlStockQuote = new HyperLink();
hlStockQuote.Text = "MCHP Quote";
hlStockQuote.NavigateUrl = "http://quotes.nasdaq.com/asp/SummaryQuote.asp?symbol=MCHP&selected=MCHP";
tcStockQuote.Controls.Add(hlStockQuote);
trStockTicker.Cells.Add(tcStockQuote);
TableCell tcBlank = new TableCell();
tcBlank.Text = " ";
trStockTicker.Cells.Add(tcBlank);
TableCell tcQuoteText = new TableCell();
tcQuoteText.Text = "(NASDAQ Exchange - quotes delayed 15 min)";
trStockTicker.Cells.Add(tcQuoteText);
trStockTicker.Cells.Add(tcBlank);
TableCell tcVolume = new TableCell();
tcVolume.Text = "Volume: " + volume;
trStockTicker.Cells.Add(tcVolume);
trStockTicker.Cells.Add(tcBlank);
TableCell tcLast = new TableCell();
tcLast.Text = last;
trStockTicker.Cells.Add(tcLast);
trStockTicker.Cells.Add(tcBlank);
TableCell tcChange = new TableCell();
tcChange.Text = change;
trStockTicker.Cells.Add(tcChange);
trStockTicker.Cells.Add(tcBlank);
TableCell tcPercentageChange = new TableCell();
tcPercentageChange.Text = percentgechange;
trStockTicker.Cells.Add(tcPercentageChange);
trStockTicker.Cells.Add(tcBlank);
tblStockTicker.Rows.Add(trStockTicker);
this.Controls.Add(tblStockTicker);

(Note: I added a web referrence named "Stock Quote" to refer to the web service, http://www.webservicex.net/stockquote.asmx )


The sample code using RSS Feed is as follows:


XmlTextReader rssReader;
XmlDocument rssDoc;
XmlNode nodeRss = null;
XmlNode nodeChannel = null;
XmlNode nodeItem;
rssReader = new XmlTextReader("http://www.nasdaq.com/aspxcontent/NasdaqRSS.aspx?data=quotes&symbol=MCHP");
rssDoc = new XmlDocument();
// Load the XML content into a XmlDocument
rssDoc.Load(rssReader);
XmlNodeList nodelist = rssDoc.GetElementsByTagName("description");
string description = string.Empty;
for (int i = 0; i < nodelist.Count; i++)
{
description = Convert.ToString(nodelist[i].InnerText).Trim();
}
// Loop for the tag
for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
{
// If it is the rss tag
if (rssDoc.ChildNodes[i].Name == "rss")
{
// tag found
nodeRss = rssDoc.ChildNodes[i];
}
}
// Loop for the tag
for (int i = 0; i < nodeRss.ChildNodes.Count; i++)
{
// If it is the channel tag
if (nodeRss.ChildNodes[i].Name == "channel")
{
// tag found
nodeChannel = nodeRss.ChildNodes[i];
}
}
for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
{
// If it is the item tag, then it has children tags which we will add as items to the ListView
if (nodeChannel.ChildNodes[i].Name == "item")
{
nodeItem = nodeChannel.ChildNodes[i];
//string cdata = nodeItem.Attributes["CDATA"].Value;
string desc = nodeItem["description"].InnerXml;
string decstext = nodeItem["description"].InnerText;
string[] sep = { "\table" };
string[] str = decstext.Split(sep, StringSplitOptions.None);
string strFinal = str[0].Replace("\r\n ", "");
strFinal = strFinal.Replace("\r\n ", "");
strFinal = strFinal.Replace("MCHP", "MCHP quote");
strFinal = strFinal.Replace("% Change", "");
strFinal = strFinal.Replace("Change", "");
strFinal = strFinal.Replace("Last", "(NASDAQ Exchange - quotes delayed by 15 min) ");
strFinal = strFinal.Replace("#DDDDDD", "");
//strFinal = strFinal.Replace("red", "white");
//string strRemove = strFinal.Substring(strFinal.IndexOf("/table"), strFinal.Length);
//strFinal = strFinal.Remove(strFinal.IndexOf("/table"), strFinal.);
Literal lt = new Literal();
lt.Text = strFinal;
//this.Controls.Add(lt);
Table tb = new Table();
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Controls.Add(lt);
tr.Cells.Add(tc);
tb.Rows.Add(tr);
tb.BackColor = Color.Silver;
tb.ForeColor = Color.White;
this.Controls.Add(tb);
}
}
}
}

(Note: I used NASDAQ RSS Feed (http://www.nasdaq.com/aspxcontent/NasdaqRSS.aspx?data=quotes&symbol=MCHP) to get the Microchip Stock details.


2) Deploy the web part to your Sharepoint Site.

3) Modify the SharePoint HomePage to include the above stock web part.


i) Open SharePoint Designer and open your site form "Open Site".
ii) Checkout your home page and open it.
iii) From the top menu, Select "Task Panes" and selct "Web Parts", which will open the web parts available for the site in the right side window.
iv) Select the Stockticker Web Part from the web parts list and drag and drop in the home page where eber required.
v) Add the following Javascript to refresh the Stock Ticker every 15 minutes.



vi) Check in the file and check your site home page to see the Stock details.

Javascrip in SharePoint

To refer Javascript file in Sharepoint 2007,

1) Go to "1033" folder in Layouts folder( c:\program files\common files\microsoft shared\web server extensions\12\template\Layouts\1033). This is the default folder that Sharepoint 2007 refers for Javascript files.


2) Add your custom javascript file in the folder ( for example, StockTicker.js file to refresh the control, with code as
var intervalID;
intervalID = window.setInterval("refreshStockTicker()",3000);
function refreshStockTicker() {document.execCommand("Refresh");};

3) To refer that javascript file in SharePoint, go to the sharepoint page using SharePoint Designer. And, refer it with the "SharePoint:ScriptLink" and "Name" as Javascript file name like,


if (!StockTicker1.IsClientScriptBlockRegistered("refreshCode"))
{ StockTicker1.RegisterClientScriptBlock("refreshCode", code); }


In above, StockTicker1 is the name of the control to be refreshed for every 3 seconds.

Thursday, November 06, 2008

How To Deploy Web Parts in MOSS 2007

Requirement: Deploy Web Part to SharePoint Site.

Procedure:
  1. Build your Web Part with Strong Name: Create a ClassLibrary Project.
  2. Drag and Drop the CustomWebPart.dll to GAC (C:\Windows\Assembly).
  3. Open the VirtualDirectories Folder (C:\Inetpub\wwwroot\wss\VirtualDirectories) and go to the Root Folder of your site. ( For Example your site is "http://localhost:801/sites/TestSite", then open the folder "801".)
  4. Open web.config file and add an SafeControl entry for your web part like, (Note: PublicKeyToken can be copied from GAC).
  5. Reset IIS
  6. Go to your site and Click on "Site Settings" => "Web parts".
  7. Click on "New" web part and Select your Web part and click on "Populate Gallary".
  8. Now go to your site and click on edit page. Click "Add a Web part". Select your web part under "Miscellaneous" section and click on "Add".
  9. You can see your web part now.
Deploy Web part by building Cab file.
  1. Build your Web Part with Strong Name: Create a ClassLibrary Project.
  2. Drag and Drop the CustomWebPart.dll to GAC (C:\Windows\Assembly).
  3. Add "CustomWepPartCab" cab project to the above solution(File => New => Project => Other Project Types => Setup and Deployment Project => Cab Project => "CustomWepPartCab")
  4. Add "Project Output.." by right click on cab project.
  5. Select "Primary output" and "Content Files".
6. Add a new file "manifest.xml" to the cab project as follows:
Note: Please make sure that file name(manifest.xml) is not changed

"











"

7. Add another file with name "CustomWebPart.dwp", the name given in the maifest.xml file as follows:
"

Custom Webpart
Custom Webpart
CustomWebpart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b6ad7af95de74642 publickeytoken value from GAC
CustomWebpart.CustomWebpart

"

Deploying the Cab file:
  1. Go to command prompt(Start => Run => Cmd)
  2. Change the directory to the location where cab file(CustomWebPart.cab) is build.
  3. Execute the following command
  4. stsadm.exe -o addwppack -filename WebPartCab.CAB -url http://SiteUrltoInstallWebPart -globalinstall -force