Is it possible to get a perticular file from sharepoint instead of getting all files at onlce?
In below query when I queryNode is empty I am getting all the files but when queryNode is commented query I am not getting any file.
What is missing here?
XmlDocument xmlDoc = new XmlDocument();
XmlNode queryNode = xmlDoc.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "Query", ""));
//queryNode.InnerXml = "<Where>" +
// " <Eq>" +
// " <FieldRef Name='FileLeafRef'></FieldRef>" +
// " <Value Type='File'>" + SomeFileName + "</Value>" +
// " </Eq>" +
// "</Where>";
queryNode.InnerText = "";
XmlDocument xmlDoc1 = new XmlDocument();
XmlNode viewNode = xmlDoc.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", ""));
viewNode.InnerXml = "";
XmlDocument xmlDoc2 = new XmlDocument();
XmlNode optionsNode = xmlDoc.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", ""));
optionsNode.InnerText = "";
XmlNode nodeListItems = wsList.GetListItems("Documents",
"",
queryNode,
viewNode,
"1",
optionsNode,
null);
This will retrieve all items in a list with a filename of "filename" only.
var list = web.Lists["ListTitle"];
var fileQuery = new SPQuery();
fileQuery .ViewAttributes = "Scope=\"Recursive\"";
string strQuery = "<Where>" +
"<Eq>" +
"<FieldRef Name=\"FileLeafRef\"/>" +
"<Value Type=\"Text\">" + fileName + "</Value>" +
"</Eq>" +
"</Where>";
fileQuery .Query = strQuery ;
SPListItemCollection collListItems = list.GetItems(fileQuery );
Related
I am trying to build a WebPage that includes "Rating of Site". Instead of using Database i am storing two variables to compute Avg of Rating in xml file as
<?xml version="1.0" encoding="utf-8"?>
<data>
<RatingCount>6</RatingCount>
<RatingTotal>17</RatingTotal>
</data>
Here is my Logic Code Both On the Page Load and AJAX Rating Control
Page_Load()
string rootPath = Server.MapPath("~/");
if (File.Exists(rootPath + "data.xml"))
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(rootPath + "data.xml");
XmlNode ratingCount = xdoc.DocumentElement.SelectSingleNode("/data/RatingCount");
XmlNode ratingTotal = xdoc.DocumentElement.SelectSingleNode("/data/RatingTotal");
string rating = ratingTotal.InnerText;
string count = ratingCount.InnerText;
if (Convert.ToInt32(count) >= 1)
{
double resultRating = Convert.ToSingle(rating) / Convert.ToSingle(count);
Rating1.CurrentRating = Convert.ToInt32(resultRating);
lblerror.Text = resultRating + " Rating in " + count + " Totals Votes";
}
else
{
lblerror.Text = "No Votes Till Now";
}
}
Rating_Control()
string rootPath = Server.MapPath("~/");
if (File.Exists(rootPath + "data.xml"))
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(rootPath + "data.xml");
XmlNode ratingCount = xdoc.DocumentElement.SelectSingleNode("/data/RatingCount");
XmlNode ratingTotal = xdoc.DocumentElement.SelectSingleNode("/data/RatingTotal");
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter xwrite = XmlWriter.Create(rootPath + #"data.xml", settings);
xwrite.WriteStartDocument();
xwrite.WriteStartElement("data");
string r = (Convert.ToInt32(ratingCount.InnerText) + 1).ToString();
string t = (Convert.ToInt32(ratingTotal.InnerText) + Convert.ToInt32(e.Value)).ToString();
xwrite.WriteElementString("RatingCount", r);
xwrite.WriteElementString("RatingTotal", t);
xwrite.WriteEndElement();
xwrite.WriteEndDocument();
xwrite.Flush();
xwrite.Close();
}
else
{
lblerror.Text = "File Doesnt Exists";
}
Any Help will be Appreciated!
I create a list, add 2 columns and insert 2 items via c# Webservice. In SharePoint I cannot see the 2 columns, only Title. When I edit the items, I see the other columns. In SharePoint I can change the view to see the 2 columns. But how to change the view with Webservice?
I try this:
private void SetView(string listName, string viewName, String[] arr)
{
AllViews.Views viewService = new AllViews.Views();
viewService.Credentials = System.Net.CredentialCache.DefaultCredentials;
//from msdn
//string strQuery1 = "<Where><Gt><FieldRef Name=\"Title\" />" +
// "<Value Type=\"Title\"></Value>" + "</Gt></Where>" +
// "<OrderBy><FieldRef Name=\"Title\" /></OrderBy>";
string strQuery = "<Query><Where><IsNotNull><FieldRef Name=\"Title\" />" +
"</IsNotNull></Where></Query>";
string strRowLimit = "150";
string strViewFields = "";
int count = arr.Length;
for (int i = 0; i < count; i++)
{
strViewFields += "<FieldRef Name=\'" + arr[i] + "\'/>";
}
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
System.Xml.XmlNode ndRowLimit = xmlDoc.CreateNode(XmlNodeType.Element, "RowLimit", "");
System.Xml.XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
ndQuery.InnerXml = strQuery;
ndRowLimit.InnerXml = strRowLimit;
ndViewFields.InnerXml = strViewFields;
XmlNode retNode = viewService.AddView(listName, viewName, ndViewFields, ndQuery, ndRowLimit, "HTML", false)
}
All without error, but columns hidden in the list. Maybe the query is wrong. Or the way that I use. Any tipps for me? Searching results are all about the SharePoint.dll, but I need a way with Webservice.
Solution
Change strQuery to:
string strQuery = "<Where><IsNotNull><FieldRef Name=\"Title\" />" +
"</IsNotNull></Where>";
// is in Node ndQuery, dont need it again. Maybe a dirty trick to hide new Columns
Set the new View as default with UpdateView. Be sure to use the GUID from the view.
For viewProperties only the prop that you want to change
string strProp = "DefaultView =\"TRUE\"";
All works fine. Have a nice weekend.
I want to send XML file as input to XML Webservice and receive output as XML.
Following code is my first attempted:
XmlDocument node = new XmlDocument();
node.LoadXml("<IDV>" +
"<start_date>" + "25/12/2014" + "</start_date>"<br>
"<vehicle_class_cd>" + "45" + "</vehicle_class_cd>"
"<RTOLocation>" + "10416" + "</RTOLocation>"
"<vehiclemodelcode>" + "22647" + "</vehiclemodelcode>"
"<manufacturer_code>" + "12474" + "</manufacturer_code>"
"<purchaseregndate>" + "27" + "</purchaseregndate>"
"<manufacturingyear>" + "2014" + "</manufacturingyear>"
"</IDV>");
demo.Service src = new demo.Service();
var str = src.getIDV(node.ToString());
I'm trying to get the inner text from a XML tag called sharecount, I need to get it by the normalized_url tag like so:
string ShareCount;
string Url = "'" + "http://www.example.com/Article.aspx?id=" + GuideID + "'";
XmlNode Node;
try
{
//return Share count (using Xpath).
XmlDoc.SelectSingleNode("fql_query_response/link_stat[normalized_url=" + Url + "]/share_count");
ShareCount = XmlDoc.InnerText;
int.TryParse(ShareCount, out Value); //Turn string to int.
return Value;
}
catch
{
return 0;
}
and this is the XML:
<fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
<link_stat>
<url>http://www.example.com/Article.aspx?id=1909</url>
<normalized_url>http://www.example.com/Article.aspx?id=1909</normalized_url>
<share_count>11</share_count>
<like_count>3</like_count>
<comment_count>0</comment_count>
<total_count>14</total_count>
<commentsbox_count>8</commentsbox_count>
<comments_fbid>10150846665210566</comments_fbid>
<click_count>0</click_count>
</link_stat>
</fql_query_response>
<link_stat>
<url>http://www.example.com/Article.aspx?id=1989</url>
<normalized_url>http://www.example.com/Article.aspx?id=1989</normalized_url>
<share_count>11</share_count>
<like_count>3</like_count>
<comment_count>0</comment_count>
<total_count>14</total_count>
<commentsbox_count>8</commentsbox_count>
<comments_fbid>10150846665210566</comments_fbid>
<click_count>0</click_count>
</link_stat>
</fql_query_response>
The thing is i got in the return value: "www.example.com/Article.aspx?id=1132http://www.example.com/Article.aspx?id=190900000101502138970422760" what am i doing wrong? thanks!
The problem is you are Selecting a single node but obtaining the content from the root element. On top of that, you have a root namespace, therefore use of NameSpaceManger for searches is required. Try this sample:
string GuideID = "1989";
string Url = "'" + "http://www.example.com/Article.aspx?id=" + GuideID + "'";
var XmlDoc = new XmlDocument();
XmlDoc.Load(new FileStream("XMLFile1.xml",FileMode.Open,FileAccess.Read));
var nsm = new XmlNamespaceManager(XmlDoc.NameTable);
nsm.AddNamespace("s", "http://api.facebook.com/1.0/");
var node = XmlDoc.SelectSingleNode("s:fql_query_response/s:link_stat[s:normalized_url=" + Url + "]/s:share_count", nsm);
var ShareCount = node.InnerText;
And here is the LINQ way with same namespace manager and an XPathSelector.
XDocument xdoc = XDocument.Load(new FileStream("XMLFile1.xml", FileMode.Open, FileAccess.Read));
var lnode = xdoc.XPathSelectElements("s:fql_query_response/s:link_stat[s:normalized_url=" + Url + "]/s:share_count",nsm).First();
var ret = lnode.Value;
I just received an error a while ago from this code:
private void ShowXMLDatatoRTB() {
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("XMLFile.xml");
var persons = from person in xmlDoc.Descendants("Person")
select new
{
Name = person.Element("Name").Value,
City = person.Element("City").Value,
Age = person.Element("Age").Value,
};
richTextBox1.Text = "";
foreach (var person in persons)
{
richTextBox1.Text = richTextBox1.Text + "Name: " + person.Name + "\n";
richTextBox1.Text = richTextBox1.Text + "City: " + person.City + "\n";
richTextBox1.Text = richTextBox1.Text + "Age: " + person.Age + "\n\n";
}
if (richTextBox1.Text == "")
richTextBox1.Text = "No Results."; }
Am I missing something?
You just need to switch from XmlDocument to XDocument.
You are trying to use LINQ to SQL but actually using the old school DOM API. You need to add references to System.XML and System.Xml.Linq and use XDocument, not XmlDocument.
Use
XDocument xmlDoc = new XDocument();
intead of
XmlDocument xmlDoc = new XmlDocument(); `