Kuongeza webreference kwa Lists.asmx katika tovuti SharePoint.
http://kwenye localhost / _vti_bin / Lists.asmx
(SharePoint virtual Directory URL / _vti_bin / Lists.asmx
kuandika mbinu zifuatazo katika webservice yako.
binafsi data.DataTable GetDataTableFromWSS(bool onlySchema)
{
string WssSiteUrl = http://192.168.111.21;
string WssSiteUrl = ConfigurationSettings.AppSettings[“WssSiteUrl”];
WssSite.Lists orodha = mpya WssSite.Lists();
lists.Url = WssSiteUrl + “_vti_bin / Lists.asmx”;
lists.Credentials = System.Net.CredentialCache.DefaultCredentials;
lists.PreAuthenticate = kweli;
//una kupita Jina Orodha ya hapa
string CommandText = “Mfanyakazi Info”;
XmlNode = ListCollectionNode lists.GetListCollection();
Orodha ya XmlElement = (XmlElement)ListCollectionNode.SelectSingleNode(String.Format(“WSS:Orodha[@ Title = '{0}’]”, CommandText), NameSpaceMgr);
kama (Orodha == null)
{
kutupa ArgumentException mpya(String.Format(“orodha ya {0} haikuweza kupatikana katika tovuti {1}”, CommandText, WssSiteUrl));
}
string TechListName = List.GetAttribute(“Jina”);
data.DataTable matokeo = mpya data.DataTable(“orodha ya”);
XmlNode ListInfoNode = lists.GetList(TechListName);
System.Text.StringBuilder fieldRefs = mpya System.Text.StringBuilder();
System.Collections.Hashtable DisplayNames = mpya System.Collections.Hashtable();
foreach (XmlElement Field katika ListInfoNode.SelectNodes(“WSS:Mashamba / WSS:Shamba”, NameSpaceMgr))
{
kama (Field.HasChildNodes)
{
foreach (XmlElement Fld katika Field.SelectNodes(“WSS:Mashamba / WSS:Shamba”, NameSpaceMgr))
{
string FieldName = Fld.GetAttribute(“Jina”);
string FieldDisplayName = Fld.GetAttribute(“DisplayName”);
kama (result.Columns.Contains(FieldDisplayName))
{
FieldDisplayName = FieldDisplayName + ” (” + FieldName + “)”;
}
result.Columns.Add(FieldDisplayName, TypeFromField(Shamba));
fieldRefs.AppendFormat(“”, FieldName);
DisplayNames.Add(FieldDisplayName, FieldName);
}
}
mwingine
{
string FieldName = Field.GetAttribute(“Jina”);
string FieldDisplayName = Field.GetAttribute(“DisplayName”);
kama (result.Columns.Contains(FieldDisplayName))
{
FieldDisplayName = FieldDisplayName + ” (” + FieldName + “)”;
}
result.Columns.Add(FieldDisplayName, TypeFromField(Shamba));
fieldRefs.AppendFormat(“”, FieldName);
DisplayNames.Add(FieldDisplayName, FieldName);
}
}
kama (onlySchema) kurudi matokeo;
XmlElement mashamba = ListInfoNode.OwnerDocument.CreateElement(“ViewFields”);
fields.InnerXml = fieldRefs.ToString();
XmlNode ItemsNode = lists.GetListItems(TechListName, “”, sifuri, mashamba, “1000000”, sifuri);
// Luke mashamba daima kuanza na ID numeric, basi ;# na kisha uwakilishi string.
// Sisi ni kawaida tu nia ya jina, hivyo sisi strip ID.
System.Text.RegularExpressions.Regex CheckLookup = mpya System.Text.RegularExpressions.Regex(“^ D ;#”);
foreach (XmlElement Item katika ItemsNode.SelectNodes(“rs:Tarehe / z:mstari”, NameSpaceMgr))
{
data.DataRow newRow = result.NewRow();
foreach (data.DataColumn kona katika result.Columns)
{
kama (Item.HasAttribute(“ows_” + (string)DisplayNames[col.ColumnName]))
{
string Val = Item.GetAttribute(“ows_” + (string)DisplayNames[col.ColumnName]);
kama (CheckLookup.IsMatch((string)Val))
{
string = valString uchaguzi kama String;
Val = valString.Substring(valString.IndexOf(“#”) + 1);
}
// Kupeana string kwa shamba hilo inatarajia idadi au
// maadili datetime itakuwa inamuunga kubadili yao
newRow[na] = Val;
}
}
result.Rows.Add(newRow);
}
kurudi matokeo;
}
// Kazi zifuatazo hutumika Kupata Namespaces
binafsi tuli XmlNamespaceManager _nsmgr;
binafsi tuli XmlNamespaceManager NameSpaceMgr
{
kupata
{
kama (_nsmgr == null)
{
_nsmgr = mpya XmlNamespaceManager(mpya NameTable());
_nsmgr.AddNamespace(“WSS”, “http://schemas.microsoft.com / SharePoint / sabuni /”);
_nsmgr.AddNamespace(“na”, “uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882”);
_nsmgr.AddNamespace(“DT”, “uuid:C2F41010-65B3-11d1-A29F-00AA00C14882”);
_nsmgr.AddNamespace(“rs”, “urn:schemas-Microsoft-com:rowset”);
_nsmgr.AddNamespace(“ya”, “#RowsetSchema”);
}
kurudi _nsmgr;
}
}
binafsi Aina TypeFromField(XmlElement shamba)
{
kubadili (field.GetAttribute(“Aina ya”))
{
kesi “DateTime”:
kurudi typeof(DateTime);
kesi “Integer”:
kurudi typeof(int);
kesi “Idadi”:
kurudi typeof(kuelea);
default:
kurudi typeof(string);
}
}
WssSite object on this code, I am getting error on this, “you are missing a using directive or an assembly reference?” any idea
Hi Bala,
WssSite is an Webreference for the lists.asmx
Cheers,
Uday
Excellent. Thanks Uday. Your post saved me lot of time in my migration project 🙂
You are welcome Jaya