Infopath error while creating dataconnection - infopath2010

I created a SOAP webservice to use in infopath form and added the method which returns a data table as return type. When i try to add the dataconnection the method it gives me an error stating that "The selecetd XML document can not be used a data connection source because it includes inline XDR schemas".
Here is the webmethod i wrote. it works well run it in the browser.
[WebMethod]
public DataTable GetApplications()
{
DataTable dt;
using (SPSite mysite = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb myweb = mysite.OpenWeb())
{
SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = "<Lists ServerTemplate=\"115\" />";
query.ViewFields = "<FieldRef Name=\"Applicant File Number\" Nullable=\"TRUE\" Type=\"Text\" />" +
"<FieldRef Name=\"Application Category \" Nullable=\"TRUE\" Type=\"Text\"/>" +
"<FieldRef Name=\"Application Type \" Nullable=\"TRUE\" Type=\"Text\"/>" +
"<FieldRef Name=\"Submission ID \" Nullable=\"TRUE\" Type=\"Text\"/>";
query.Query = "<OrderBy>" +
"<FieldRef Name=\"Submission ID\" />" +
"</OrderBy>";
query.Webs = "<Webs Scope=\"SiteCollection\" />";
dt= myweb.GetSiteData(query);
dt.TableName = "myApplications";
return dt;
}
}
}

Added the data table to a dataset and returned the dataset to infopath form through dataconnection. It worked well.

Related

How to validate if SharePoint list item update was successfull

I am trying to update a SharePoint list through an InfoPath form. A starting date SelectedDAM is input, and the code then calculates 6 dates. Newly calculated dates have to be updated in the original SP list.
The code below raises no exception in debug mode, and even in production. I checked that 'jobs' gets populated with data, and that le list names are as per their SharePoint name. Saddly, when I look to the SharePoint list afterward, items were not updated.
public void SetDAMButton_Clicked(object sender, ClickedEventArgs e)
{
string SelectedCEC = nav.SelectSingleNode("/my:mesChamps/my:DAMSection/my:CEC", this.NamespaceManager).Value;
string SelectedDAM = nav.SelectSingleNode("/my:mesChamps/my:DAMSection/my:DAM", this.NamespaceManager).Value;
//Query all jobs and dates from SharePoint List
XmlDocument xmlDoc = new XmlDocument();
XmlNode query = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode viewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
query.InnerXml = "<Where>" +
"<Contains><FieldRef Name='CEC'/>" +
"<Value Type='Text'>" + SelectedCEC.Trim() + "</Value></Contains>" +
"</Where>";
viewFields.InnerXml = "<FieldRef Name='ID' />" +
"<FieldRef Name='JRS_x0020_Avant' />"+ "<FieldRef Name='JRS_x0020_Pr_x00e9_vus' />"+
"<FieldRef Name='JRS_x0020_Prevus_x0020_2' />"+ "<FieldRef Name='JRS_x0020_Avant_x0020_2' />"+
"<FieldRef Name='JRS_x0020_Pr_x00e9_vus_x0020_3' />" + "<FieldRef Name='JRS_x0020_Avant_x0020_3' />";
XmlNode listItems = sp.getListService().GetListItems(SPJobsListGlobal, null, query, viewFields, "10000000", null, null);
//Extract jobs data to an internal list
List<string[]> jobs = new List<string[]>();
for (int i = 1; i != listItems.ChildNodes[1].ChildNodes.Count; i += 2)
{
string jobId = listItems.ChildNodes[1].ChildNodes[i].Attributes[0].InnerXml;
string JRSAvant = listItems.ChildNodes[1].ChildNodes[i].Attributes[1].InnerXml;
string JRSPrevus = listItems.ChildNodes[1].ChildNodes[i].Attributes[2].InnerXml;
string JRSPrevus2 = listItems.ChildNodes[1].ChildNodes[i].Attributes[3].InnerXml;
string JRSAvant2 = listItems.ChildNodes[1].ChildNodes[i].Attributes[4].InnerXml;
string JRSPrevus3 = listItems.ChildNodes[1].ChildNodes[i].Attributes[5].InnerXml;
string JRSAvant3 = listItems.ChildNodes[1].ChildNodes[i].Attributes[6].InnerXml;
jobs.Add(new string[] { jobId.Trim(), JRSAvant.Trim(), JRSPrevus.Trim(),JRSAvant2.Trim(), JRSPrevus2.Trim(), JRSAvant3.Trim(), JRSPrevus3.Trim() });
}
jobs.RemoveAt(jobs.Count - 1);
//Update each item of SharePoint list with dates calculated from new DAM
for(int i = 0; i != jobs.Count; i++)
{
XmlDocument doc = new XmlDocument();
XmlElement batch = doc.CreateElement("Batch");
batch.InnerXml = "<Method ID='1' Cmd='Update'>" +
"<Field Name='ID'>" + SecurityElement.Escape(jobs[i][0]) + "</Field>" +
"<Field Name='DateDebut'>" + SecurityElement.Escape(Convert.ToDateTime(SelectedDAM).AddDays(-validateJRS(jobs[i][1])).ToString("yyyy-MM-dd")) + "</Field>" +
"<Field Name='DateFin'>" + SecurityElement.Escape(Convert.ToDateTime(SelectedDAM).AddDays(-validateJRS(jobs[i][1])).AddDays(validateJRS(jobs[i][2])).ToString("yyyy-MM-dd")) + "</Field>" +
"<Field Name='Date_x0020_D_x00e9_but_x0020_2'>" + SecurityElement.Escape(Convert.ToDateTime(SelectedDAM).AddDays(-validateJRS(jobs[i][3])).ToString("yyyy-MM-dd")) + "</Field>" +
"<Field Name='Date_x0020_Fin_x0020_2'>" + SecurityElement.Escape(Convert.ToDateTime(SelectedDAM).AddDays(-validateJRS(jobs[i][3])).AddDays(validateJRS(jobs[i][4])).ToString("yyyy-MM-dd")) + "</Field>" +
"<Field Name='Date_x0020_D_x00e9_but_x0020_3'>" + SecurityElement.Escape(Convert.ToDateTime(SelectedDAM).AddDays(-validateJRS(jobs[i][5])).ToString("yyyy-MM-dd")) + "</Field>" +
"<Field Name='Date_x0020_Fin_x0020_3'>" + SecurityElement.Escape(Convert.ToDateTime(SelectedDAM).AddDays(-validateJRS(jobs[i][5])).AddDays(validateJRS(jobs[i][6])).ToString("yyyy-MM-dd")) + "</Field>" +
"</Method>";
sp.UpdateListItems(SPJobsListGlobal, batch);
}
Why is it not working ? Is there any additionnal line I could add to confirm update.
To confirm the update you can check the return value of Lists.UpdateListItems, which is an XmlNode that contains the status of the update.
From MSDN:
Return value
An XMLDATA fragment in the following form that shows the status of each method block posted through the updates parameter and that can be assigned to a System.Xml.XmlNode object. For items successfully updated, a row fragment is returned with the updated row values.

giving "Microsoft sharepoint soapserver soap server exception" while getting the list items

I am trying to get the list items by using the webservice reference model.
I am trying to get the details of the list as this
SPSeriveReference.Lists client = new SPSeriveReference.Lists();
client.Credentials = new NetworkCredential("Administrator", "pswd","MyDomain");
XmlDocument mydoc = new XmlDocument();
XmlElement viewFileds = mydoc.CreateElement("ViewFields");
viewFileds.InnerXml = "<FieldRef Name=\"Title\" />" +
"<FieldRef Name=\"Name\" />" +
"<FieldRef Name=\"Address\" />";
XmlNode listItems = client.GetListItems("Manager", null, null, viewFileds, null, null, null); //a4af13f3-69f6-45e3-930d-8c2ce61a10fd
//XmlNode listItems = client.GetListItems("Manager", null, null, viewFileds, null, null, null);
foreach (XmlNode node in listItems)
{
if (node.Name == "rs:data")
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
if (node.ChildNodes[i].Name=="z:row")
{
string title = node.ChildNodes[i].Attributes["ows_Title"].Name;
string name = node.ChildNodes[i].Attributes["ows_Name"].Name;
string address = node.ChildNodes[i].Attributes["ows_Address"].Name;
Console.WriteLine(title + " " + name + " " + address);
}
}
}
}
But this is giving run time exception as "Microsoft.SharePoint.SoapServer.SoapServerException"
What is the solution for this one?
I verified the questions in stack overflow which were asked previously regarding the same error. But none of the provided the solution for this problem.

Need to find a SPItem without knowing the ID of the item

I have two lists and one event receiver. The event receiver sets a column of the list to a unique identifier (combo of the content type and the item id).
In the other list I use query string and the newform to set a field to the very same unique identifier above. I also gather some more info in that newform I want to work with.
How can I query a list without knowing the ID, but I have another unique id to single out from the other items so I can work with it just as SPitem firstitem below so I can find the other fields.
Getting my first item to get the unique title:
SPSite currentSite = SPContext.Current.Site;
SPWeb web = currentSite.OpenWeb();
string queryString = Request.QueryString["uniqueID"];
SPList firstList = web.Lists["My First List"];
SPItem firstItem = firstList.Items.GetItemById(Convert.ToInt32(queryString));
this is the unique title I want to query second list with:
string uniqueTitle = firstItem["Title"].ToString();
getting my second list up, ready for action:
SPList secondList = web.Lists["My Second List"];
Thanks
ANSWER:
// open the second list
SPList secondList = web.Lists["My Second List"];
// Query the second list for the item
SPQuery myQuery = new SPQuery();
myQuery.Query = "<Where><Eq><FieldRef Name = \"Title\"/>" +
"<Value Type = \"Text\">" + uniqueTitle +
"</Value></Eq></Where>";
// Get a collection of the second list items selected by the query and pick the first (0) value as it should only return one!
SPListItemCollection secondlistItemCol = secondList.GetItems(myQuery);
SPListItem secondItem = secondlistItemCol[0];
You will want to use the GetItems command with an SPQuery object. It is not too complex to sort out with the MS code example below.
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://localhost"))
{
using (SPWeb web = site.OpenWeb())
{
// Build a query.
SPQuery query = new SPQuery();
query.Query = string.Concat(
"<Where><Eq>",
"<FieldRef Name='Status'/>",
"<Value Type='CHOICE'>Not Started</Value>",
"</Eq></Where>",
"<OrderBy>",
"<FieldRef Name='DueDate' Ascending='TRUE' />",
"<FieldRef Name=’Priority’ Ascending='TRUE' />",
"</OrderBy>");
query.ViewFields = string.Concat(
"<FieldRef Name='AssignedTo' />",
"<FieldRef Name='LinkTitle' />",
"<FieldRef Name='DueDate' />",
"<FieldRef Name='Priority' />");
query.ViewFieldsOnly = true; // Fetch only the data that we need.
// Get data from a list.
string listUrl = web.ServerRelativeUrl + "/lists/tasks";
SPList list = web.GetList(listUrl);
SPListItemCollection items = list.GetItems(query);
// Print a report header.
Console.WriteLine("{0,-25} {1,-20} {2,-25} {3}",
"Assigned To", "Task", "Due Date", "Priority");
// Print the details.
foreach (SPListItem item in items)
{
Console.WriteLine("{0,-25} {1,-20} {2,-25} {3}",
item["AssignedTo"], item["LinkTitle"], item["DueDate"], item["Priority"]);
}
}
}
Console.ReadLine();
}
}
}

Get the URL of a List in sharepoint using Caml Query

I am using SPSiteDataQuery to display documents from different lists. I display the documents using a Gridview. One of the columns of the Gridview is an hyperlinkfield. How can I set the url of each document since each of them comes from different different document libraries? For your information, I am using Caml Query to filter the documents.
Please help me.
here is the code:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Data;
using Microsoft.SharePoint.Utilities;
namespace Uniway.FOD.Intranet.ControlTemplates
{
public partial class Documents : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = GetAllDocuments();
// Set up the field bindings.
BoundField boundField = new BoundField();
boundField.HeaderText = "File name";
boundField.DataField = "Title";//"LinkFilename";
GridView1.Columns.Add(boundField);
HyperLinkField hyperlinkField = new HyperLinkField();
hyperlinkField.HeaderText = "Link name";
hyperlinkField.DataTextField = "LinkFileName";
hyperlinkField.DataNavigateUrlFields = new[] { "LinkFileName" };
hyperlinkField.DataNavigateUrlFormatString = "{0}";
GridView1.Columns.Add(hyperlinkField);
BoundField boundField2 = new BoundField();
boundField2.HeaderText = "Link File Name";
boundField2.DataField = "LinkFilename";
GridView1.Columns.Add(boundField2);
GridView1.DataBind();
}
public DataTable GetAllDocuments()
{
SPSiteDataQuery objSPSiteDataQuery = null;
SPWeb objSPWeb = null;
DataTable objDataTable = null;
objSPWeb = SPContext.Current.Web;
objSPSiteDataQuery = new SPSiteDataQuery();
//Specify the fields to be fetched in the results.Similar to select clause of an SQL query
objSPSiteDataQuery.ViewFields = "<FieldRef Name=\"LinkFilename\"/>" +
"<FieldRef Name=\"Title\" />" +
"<FieldRef Name=\"Created\" />" +
"<FieldRef Name=\"Modified\"/>" +
"<FieldRef Name=\"Editor\"/>";
//specifying list server template=101 so that it will query only document libraries
objSPSiteDataQuery.Lists = "<Lists ServerTemplate=\"101\" BaseType=\"1\" Hidden=\"FALSE\" MaxListsLimit=\"0\"/>";
objSPSiteDataQuery.RowLimit = 1000;
objSPSiteDataQuery.Webs = "<Webs Scope=\"Recursive\"/>";
//querying all documents of the content type 'CT23December1' having version=1.0
objSPSiteDataQuery.Query = #"<Where>
<Eq>
<FieldRef Name='File_x0020_Type' />
<Value Type='Text'>doc</Value>
</Eq>
</Where><OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy>";
objDataTable = objSPWeb.GetSiteData(objSPSiteDataQuery);
return objDataTable;
}
}
}
You can use some internal fields to build a link to the document. Here are some useful ones with an example of the data in each field:
FileRef - 1;#sites/SiteCollection/Kit/Kits Site Documents/Excel Report.xls
FileLeafRef - 1;#Excel Report.xls
FileDirRef - 1;#sites/SiteCollection/Kit/Kits Site Documents
ServerUrl - /sites/SiteCollection/Kit/Kits Site Documents/Excel Report.xls
EncodedAbsUrl - http://server/sites/SiteCollection/Kit/Kits%20Site%20Documents/Excel%20Report.xls
You'll just add one of the fields above as another viewfield to objSPSiteDataQuery.ViewFields:
objSPSiteDataQuery.ViewFields = "<FieldRef Name=\"ServerUrl\"/>" +
"<FieldRef Name=\"LinkFilename\"/>" +
"<FieldRef Name=\"Title\" />" +
"<FieldRef Name=\"Created\" />" +
"<FieldRef Name=\"Modified\"/>" +
"<FieldRef Name=\"Editor\"/>";
I did it like this:
row["AbsolutePath"] = String.Format("{0}{1}", row["EncodedAbsUrl"], row["FileRef"].ToString().Substring(row["FileRef"].ToString().IndexOf("#") + 1));

Problem in SharePoint Object model when accessing the sharepoint list items?

just i wrote
using (SPSite site = SPContext.Current.Site)
{
using (SPWeb web = site.OpenWeb())
{
//SPList lst = web.Lists["ManagerInfo"];
SPList lst = web.Lists[strlist];
SPQuery getUserNameQuery = new SPQuery();
// getUserNameQuery.Query = "<Where><And><Eq><FieldRef Name=\"Region\" /><Value Type=\"Text\">" + strRegion + "</Value></Eq><And><Eq><FieldRef Name=\"PM_x0020_First_x0020_Name\" /><Value Type=\"Text\">" + pmFName + "</Value></Eq><Eq><FieldRef Name=\"PM_x0020_Last_x0020_Name\" /><Value Type=\"Text\">" + pmLname + "</Value></Eq></And></And></Where>";
// getUserNameQuery.Query = "<Where><And><Eq><FieldRef Name=\"PM_x0020_First_x0020_Name\" /><Value Type=\"Text\">" + pmFName + "</Value></Eq><Eq><FieldRef Name=\"PM_x0020_Last_x0020_Name\" /><Value Type=\"Text\">" + pmLname + "</Value></Eq></And></Where>";
getUserNameQuery.Query = "<Where><Eq><FieldRef Name=\"PM_x0020_Name\" /><Value Type=\"Text\">" + loginName + "</Value></Eq></Where>";
SPListItemCollection items = lst.GetItems(getUserNameQuery);
foreach (SPListItem item in items)
{
managerFName = item["Manager Name"].ToString();
strAccounting = item["Accounting"].ToString();
managerFName = managerFName.Replace(".", " ");
strAccounting = strAccounting.Replace(".", " ");
// isFound = true;
XPathNavigator managerName = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:txtManagerName", NamespaceManager);
managerName.SetValue(managerFName);
XPathNavigator accountingName = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:txtAccountingName", NamespaceManager);
accountingName.SetValue(strAccounting);
}
}
}
i used this code in infopath this infopath is using by all users.os when the current login user have no permissions to the list it showing error.when the current login user have full Permission it is working.
So Please advise me what can i do inorder to work them for all users.
By using this
using (SPSite site = SPContext.Current.Site){}
You are disposing of SPContext.Current.Site which you should not do. Taking Don's suggestion into consideration as well, try this
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
//SPList lst = web.Lists["ManagerInfo"];
SPList lst = web.Lists[strlist];
SPQuery getUserNameQuery = new SPQuery();
// getUserNameQuery.Query = "<Where><And><Eq><FieldRef Name=\"Region\" /><Value Type=\"Text\">" + strRegion + "</Value></Eq><And><Eq><FieldRef Name=\"PM_x0020_First_x0020_Name\" /><Value Type=\"Text\">" + pmFName + "</Value></Eq><Eq><FieldRef Name=\"PM_x0020_Last_x0020_Name\" /><Value Type=\"Text\">" + pmLname + "</Value></Eq></And></And></Where>";
// getUserNameQuery.Query = "<Where><And><Eq><FieldRef Name=\"PM_x0020_First_x0020_Name\" /><Value Type=\"Text\">" + pmFName + "</Value></Eq><Eq><FieldRef Name=\"PM_x0020_Last_x0020_Name\" /><Value Type=\"Text\">" + pmLname + "</Value></Eq></And></Where>";
getUserNameQuery.Query = "<Where><Eq><FieldRef Name=\"PM_x0020_Name\" /><Value Type=\"Text\">" + loginName + "</Value></Eq></Where>";
SPListItemCollection items = lst.GetItems(getUserNameQuery);
foreach (SPListItem item in items)
{
managerFName = item["Manager Name"].ToString();
strAccounting = item["Accounting"].ToString();
managerFName = managerFName.Replace(".", " ");
strAccounting = strAccounting.Replace(".", " ");
// isFound = true;
XPathNavigator managerName = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:txtManagerName", NamespaceManager);
managerName.SetValue(managerFName);
XPathNavigator accountingName = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:txtAccountingName", NamespaceManager);
accountingName.SetValue(strAccounting);
}
}
}
});
try to surround your code logic with :
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// insert code here
}

Resources