Retreiving Content Lis nan WebService nan charepwen 2003

Add webreference a Lists.asmx a nan sit charepwen.

http://lokalost / _vti_bin / Lists.asmx
(Charepwen Virtual Anyè URL / _vti_bin / Lists.asmx

ekri metòd sila yo nan webservice ou.

prive data.DataTable GetDataTableFromWSS(bool onlySchema)
{
fisèl WssSiteUrl = http://192.168.111.21;
fisèl WssSiteUrl = ConfigurationSettings.AppSettings[“WssSiteUrl”];
WssSite.Lists lis = nouvo WssSite.Lists();
lists.Url = WssSiteUrl + “_vti_bin / Lists.asmx”;
lists.Credentials = System.Net.CredentialCache.DefaultCredentials;

lists.PreAuthenticate = vre;
//you have to pass the List Name here
string CommandText = “Employee Info”;
XmlNode ListCollectionNode = lists.GetListCollection();
XmlElement List = (XmlElement)ListCollectionNode.SelectSingleNode(String.Format(“wss:Lis[@Title='{0}’]”, CommandText), NameSpaceMgr);
si (List == null)
{
throw new ArgumentException(String.Format(“The list {0} could not be found in the site {1}”, CommandText, WssSiteUrl));
}
string TechListName = List.GetAttribute(“Non”);
data.DataTable result = new data.DataTable(“lis”);
XmlNode ListInfoNode = lists.GetList(TechListName);
System.Text.StringBuilder fieldRefs = new System.Text.StringBuilder();
System.Collections.Hashtable DisplayNames = new System.Collections.Hashtable();
fortch (XmlElement Field in ListInfoNode.SelectNodes(“wss:Fields/wss:Field”, NameSpaceMgr))
{
si (Field.HasChildNodes)
{
fortch (XmlElement Fld in Field.SelectNodes(“wss:Fields/wss:Field”, NameSpaceMgr))
{
string FieldName = Fld.GetAttribute(“Non”);
string FieldDisplayName = Fld.GetAttribute(“DisplayName”);
si (result.Columns.Contains(FieldDisplayName))
{
FieldDisplayName = FieldDisplayName + ” (” + Fyèldnam + “)”;
}
result.Columns.Add(FieldDisplayName, TypeFromField(Field));
fieldRefs.AppendFormat(“”, Fyèldnam);
DisplayNames.Add(FieldDisplayName, Fyèldnam);
}
}
lòt moun
{
fisèl fyèldnam = Field.GetAttribute(“Non”);
fisèl FieldDisplayName = Field.GetAttribute(“DisplayName”);
si (result.Columns.Contains(FieldDisplayName))
{
FieldDisplayName = FieldDisplayName + ” (” + Fyèldnam + “)”;
}
result.Columns.Add(FieldDisplayName, TypeFromField(Field));
fieldRefs.AppendFormat(“”, Fyèldnam);
DisplayNames.Add(FieldDisplayName, Fyèldnam);
}
}
si (onlySchema) retounen rezilta;
Jaden XmlElement = ListInfoNode.OwnerDocument.CreateElement(“ViewFields”);
fields.InnerXml = fieldRefs.ToString();
XmlNode ItemsNode = lists.GetListItems(TechListName, “”, nil, jaden, “1000000”, nil);
// Jaden Passage toujou kòmanse ak nimerik ID a, Lè sa a, ;# ak Lè sa a reprezantasyon nan fisèl.
// Nou se nòmalman sèlman ki enterese nan non an, se konsa nou dezabiye ID a.
System.Text.RegularExpressions.Regex CheckLookup = nouvo System.Text.RegularExpressions.Regex(“^ D ;#”);

fortch (XmlElement Item nan ItemsNode.SelectNodes(“rs:done / z:ranje”, NameSpaceMgr))
{
data.DataRow newRow = result.NewRow();
fortch (col data.DataColumn nan result.Columns)
{
si (Item.HasAttribute(“ows_” + (fisèl)DisplayNames[col.ColumnName]))
{
fisèl Val = Item.GetAttribute(“ows_” + (fisèl)DisplayNames[col.ColumnName]);
si (CheckLookup.IsMatch((fisèl)h))
{
valString fisèl = Val Kòm chèn;
Val = valString.Substring(valString.IndexOf(“#”) + 1);
}
// Plase yon fil nan yon jaden ki espere nimewo oswa
// valè dattim pral chal konvèti yo
newRow[ak] = H;
}
}
result.Rows.Add(newRow);
}
retounen rezilta;
}

// Se fonksyon ki anba la a itilize yo ka resevwa namèspas

prive estatik _nsmgr XmlNamespaceManager;
prive estatik XmlNamespaceManager NameSpaceMgr
{
jwenn
{
si (_nsmgr == nil)
{
_nsmgr = nouvo XmlNamespaceManager(nouvo NameTable());
_nsmgr.AddNamespace(“wss”, “http://schemas.microsoft.com/sharepoint/soap/”);
_nsmgr.AddNamespace(“ak”, “uwi:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882”);
_nsmgr.AddNamespace(“dt”, “uwi:C2F41010-65B3-11d1-A29F-00AA00C14882”);
_nsmgr.AddNamespace(“rs”, “om:chema-microsoft-com:rowset”);
_nsmgr.AddNamespace(“soti nan”, “#RowsetSchema”);

}
retounen _nsmgr;
}
}
Kalite prive TypeFromField(XmlElement jaden)
{
switch (field.GetAttribute(“Kalite”))
{
ka “Dattim”:
retounen tipeof(Dattim);
ka “Nonb antye relatif”:
retounen tipeof(int);
ka “Nimewo”:
retounen tipeof(flote);
default:
retounen tipeof(fisèl);
}
}

4 kòmantè Retreiving Lis Content nan webservice nan charepwen 2003

Leave a Reply

Ou kapab sèvi ak sa yo tags HTML

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>