Repository navigation
.NET Server Object Model # Common function
Jack Hu edited this page Aug 17, 2017
·
4 revisions
SPQuery query = new SPQuery();
query.Query = @"<OrderBy><FieldRef Name ='LinkOrder'></FieldRef></OrderBy>";
SPList list_MainList = ssweb.Lists.TryGetList(PosMainList);
SPListItemCollection mainCollection = list_MainList.GetItems(query);
List<string> list_mainCollection = mainCollection.Cast<SPListItem>().OrderBy(x => x.ToStringExtension("LinkOrder")).Select(x => x.ToStringExtension("InternalFieldName")).ToList();
List<string> fields = new List<string>();
fields.AddRange(list_mainCollection);
SPListItemCollection items = ssweb.Lists.TryGetList(listName).GetItems(fields.ToArray());
var records = items.GetDataTable().AsEnumerable();
records = records.Where(x => DateTime.Parse(x.Field<string>("Year") + "-" + x.Field<string>("Month")) <= DateTime.Parse(strs[0] + "-" + strs[1]));
DataView dv = records.AsDataView();
return records.AsDataView().ToTable();
SPWeb ssweb = SPContext.Current.Web;
ssweb.AllowUnsafeUpdates = true;
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='ItemGuid' /><Value Type='Text'>" + ItemGuid + "</Value></Eq></Where><OrderBy><FieldRef Name='Modified' Ascending='True' /></OrderBy>";
SPListItemCollection HistoryColls = ServerBuilder.GetListItemCollection(ssweb, History, query, string.Empty);
StringBuilder sbDelete = new StringBuilder();
sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
foreach (SPListItem i in HistoryColls)
{
sbDelete.Append("<Method>");
sbDelete.Append("<SetList Scope=\"Request\">" + i.ParentList.ID + "</SetList>");
sbDelete.Append("<SetVar Name=\"ID\">" + Convert.ToString(i.ID) + "</SetVar>");
sbDelete.Append("<SetVar Name=\"Cmd\">Delete</SetVar>");
sbDelete.Append("</Method>");
}
sbDelete.Append("</Batch>");
ssweb.ProcessBatchData(sbDelete.ToString());
SPDocumentLibrary FilesLib = ssweb.Lists[Files] as SPDocumentLibrary;
string FilesFolderUrl = ssweb.Url + @"/" + FilesLib.Title + @"/";
SPFolder Folder = ssweb.GetFolder(FilesFolderUrl + ItemGuid);
if (Folder != null && Folder.Exists == true)
{
Folder.Recycle();
}
ssweb.AllowUnsafeUpdates = false;
SPFieldUserValueCollection users= (SPFieldUserValueCollection)item[str];
foreach (SPFieldUserValue user in users)
{
if (user!= null && user.User != null)
{
if (user.User.Email != string.Empty)
{
string email=user.User.Email;
string name=user.User.Name;
}
}
}
public override void ItemUpdated(SPItemEventProperties properties)
{
//base.ItemUpdated(properties);
base.EventFiringEnabled = false;
item.Update();
base.EventFiringEnabled = true;
}
//In Document library event handlers during Item Updating also checking that Document is it in Check In mode or Check Out. That's why it is called twice.
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null &&
properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)
{
//do stuff
}
}
- SharePoint Maintain
- SharePoint Migration
- SharePoint PowerShell
- SharePoint eBook
- SharePoint Installation
- Pnp Guide
- Authenticate
- Get SharePoint list ItemCount
- Search User
- Set up an Office 365 developer subscription
- SharePoint Designer encountered an error generating the task form
- SharePoint JSGrid
- SharePoint ListItemPosition
- Sharepoint login as antother user
- Sharepoint Issues
- Make Attachments Mandatory In SharePoint Lists
- Datatables
- Drag
- FileSaver base64 string to file
- Jquery Zip files
- Convert base64 string to blob
- generate word
- Import Export Excel
- Remote Debug Tool
- Save base64string as file
- Linq
- HtmlToPdf
- Export to Excel
- Send Email with attachment
- Common function
- Download File
- Access SharePoint Online using Postman
- Byte[]和文件FileStream相互转化
- Generate File wiht UTF8 BOM
- Generate word
- Regex replace
- WordToPDF.dll
- ZIPFile
- 读写Excle Word
- EPPLUS
- Generate Word by Template
- Lotus Notes RichText
- SqlTransaction
- Using the Exchange Webs Services API
- VS Migrate 2010 to 2013 error
- SQL Command