SharePoint development, sharepoint

Source: Internet
Author: User

SharePoint development, sharepoint

This article describes some novel SharePoint instance applications, which have been used in projects for Party A. The data is too large and the customer has Excel, which requires batch import.

Roughly as follows:


This instance is imported by using the data view of the list. The data view is similar to Excel, so you can directly edit it, or even paste it directly from Excel, click Save to insert the data to the list.

First, we need a list. The list field corresponds to Excel. In my instance, select create list definition and list instance (how to create a project is not a waste of effort)

Create method stamp here

After the list instance is completed, add an event Receiver acting on the list to process Background operations. Add an event receiver, select Delete, added, and updated events to complete the creation.



You can write the core code. In our actual application, a temporary table is created to process the data here. Click Save on the page and then go to the real data table.

/// <Summary> /// deleting an item. /// </summary> public override void ItemDeleting (SPItemEventProperties properties) {base. itemDeleting (properties); SPListItem item = properties. listItem; SPMIPEntities entities = new SPMIPEntities (); string uniqueId = item. uniqueId. toString (); ZY_YeZhqdjch_Temp = (from p in entities. ZY_YeZhqdjch_Temp where p. uniqueId. equals (uniqueId) select p ). firstOrDefault (); entities. deleteObject (temp); entities. saveChanges ();} // <summary> // added item. /// </summary> public override void ItemAdded (SPItemEventProperties properties) {base. itemAdded (properties); SPListItem item = properties. listItem; SPMIPEntities entities = new SPMIPEntities (); ZY_YeZhqdjch_Temp temp = new ZY_YeZhqdjch_Temp (); string a = properties. userLoginName; // obtain the username string username = properties. userLoginName. substring (properties. userLoginName. indexOf ("spmipmp |") + 8); var list = from p in entities. SYS_User where (p. userCode. equals (username) select new {p. userCode, p. zhi_gid}; DataTable dt = IQueryableExtensions. toDataTable (list); // obtain the caller ID temp. chuang_jzh = Convert. toInt32 (dt. rows [0] ["Zhi_gid"]); temp. uniqueId = item. uniqueId. toString (); if (item ["Owner list Code"] = null) {temp. ye_zhqdbm = "";} else {temp. ye_zhqdbm = item ["Owner list Code"]. toString ();} if (item ["Owner list name"] = null) {temp. ye_zhqdmch = "";} else {temp. ye_zhqdmch = item ["Name of the owner list"]. toString ();} if (item ["list item feature"] = null) {temp. qing_dxmtzh = "";} else {temp. qing_dxmtzh = item ["list item features"]. toString ();} if (item ["unit"] = null) {temp. dan_w = "";} else {temp. dan_w = item ["unit"]. toString ();} if (item ["Quantity List"] = null) {temp. qing_dl = 0;} else {temp. qing_dl = Convert. toDecimal (item [""]);} if (item [""] = null) {temp. qian_zhl = 0;} else {temp. qian_zhl = Convert. toDecimal (item ["signature quantity"]);} if (item ["Acceptance quantity"] = null) {temp. yan_shl = 0;} else {temp. yan_shl = Convert. toDecimal (item ["Acceptance amount"]);} if (item ["Contract Price"] = null) {temp. he_tdj = 0;} else {temp. he_tdj = Convert. toDecimal (item ["Contract Price"]);} if (item ["owner sign price"] = null) {temp. ye_zhqrdj = 0;} else {temp. ye_zhqrdj = Convert. toDecimal (item ["owner sign unit price"]);} if (item ["estimated unit price"] = null) {temp. yu_jjsdj = 0;} else {temp. yu_jjsdj = Convert. toDecimal (item ["estimated unit price of Final Statement"]);} if (item ["estimated proportion of audited items"] = null) {temp. yu_jshjbl = 0;} else {temp. yu_jshjbl = Convert. toDecimal (item ["estimated audited percentage"]);} if (item ["final price"] = null) {temp. jue_sdj = 0;} else {temp. jue_sdj = Convert. toDecimal (item ["final unit price"]);} entities. addToZY_YeZhqdjch_Temp (temp); entities. saveChanges () ;}/// <summary> /// updated. /// </summary> public override void ItemUpdated (SPItemEventProperties properties) {base. itemUpdated (properties); SPListItem item = properties. listItem; SPMIPEntities entities = new SPMIPEntities (); string uniqueId = item. uniqueId. toString (); ZY_YeZhqdjch_Temp = (from p in entities. ZY_YeZhqdjch_Temp where p. uniqueId. equals (uniqueId) select p ). firstOrDefault (); // obtain the username string username = properties. userLoginName. substring (properties. userLoginName. indexOf ("spmipmp |") + 8); var list = from p in entities. SYS_User where (p. userCode. equals (username) select new {p. userCode, p. zhi_gid}; DataTable dt = IQueryableExtensions. toDataTable (list); // obtain the caller ID temp. chuang_jzh = Convert. toInt32 (dt. rows [0] ["Zhi_gid"]); if (item ["Owner list Code"] = null) {temp. ye_zhqdbm = "";} else {temp. ye_zhqdbm = item ["Owner list Code"]. toString ();} if (item ["Owner list name"] = null) {temp. ye_zhqdmch = "";} else {temp. ye_zhqdmch = item ["Name of the owner list"]. toString ();} if (item ["list item feature"] = null) {temp. qing_dxmtzh = "";} else {temp. qing_dxmtzh = item ["list item features"]. toString ();} if (item ["unit"] = null) {temp. dan_w = "";} else {temp. dan_w = item ["unit"]. toString ();} if (item ["Quantity List"] = null) {temp. qing_dl = 0;} else {temp. qing_dl = Convert. toDecimal (item [""]);} if (item [""] = null) {temp. qian_zhl = 0;} else {temp. qian_zhl = Convert. toDecimal (item ["signature quantity"]);} if (item ["Acceptance quantity"] = null) {temp. yan_shl = 0;} else {temp. yan_shl = Convert. toDecimal (item ["Acceptance amount"]);} if (item ["Contract Price"] = null) {temp. he_tdj = 0;} else {temp. he_tdj = Convert. toDecimal (item ["Contract Price"]);} if (item ["owner sign price"] = null) {temp. ye_zhqrdj = 0;} else {temp. ye_zhqrdj = Convert. toDecimal (item ["owner sign unit price"]);} if (item ["estimated unit price"] = null) {temp. yu_jjsdj = 0;} else {temp. yu_jjsdj = Convert. toDecimal (item ["estimated unit price of Final Statement"]);} if (item ["estimated proportion of audited items"] = null) {temp. yu_jshjbl = 0;} else {temp. yu_jshjbl = Convert. toDecimal (item ["estimated audited percentage"]);} if (item ["final price"] = null) {temp. jue_sdj = 0;} else {temp. jue_sdj = Convert. toDecimal (item ["final unit price"]);} entities. saveChanges ();}

Next, we want to be more automated. We will automatically create a data view for this list and set it to the default view for specialized import operations.

Process the FeatureActivated event. The core code in the instance is as follows:

SPWeb _ web = properties. feature. parent as SPWeb; SPList list = _ web. lists. tryGetList ("basic owner list import"); SPList listTwo = _ web. lists. tryGetList ("internal list basic import"); SPView newView = null; SPView newViewTwo = null; string strQuery = default (string); string strQueryTwo = default (string ); stringCollection strCol = new StringCollection (); StringCollection strColTwo = new StringCollection (); newView = list. views. cast <SPView> (). firstOrDefault (v => v. title = "Owner list basics"); if (newView = null) {strCol. clear (); strCol. add ("Title"); strCol. add ("Ye_zhqdmch"); strCol. add ("Qing_dxmtzh"); strCol. add ("Dan_w"); strCol. add ("Qing_dl"); strCol. add ("Qian_zhl"); strCol. add ("Yan_shl"); strCol. add ("He_tdj"); strCol. add ("Ye_zhqrdj"); strCol. add ("Yu_jjsdj"); strCol. add ("Yu_jshjbl"); strCol. add ("Jue_sdj"); newView = list. views. add ("Default", strCol, strQuery, 30, true/** // * Whether paging is supported */, true/** // * whether it is the Default view */, Microsoft. sharePoint. SPViewCollection. SPViewType. grid, false); newView. title = "Owner list basics"; newView. update ();} newViewTwo = listTwo. views. cast <SPView> (). firstOrDefault (v => v. title = "internal configuration basics"); if (newViewTwo = null) {strColTwo. clear (); strColTwo. add ("Title"); strColTwo. add ("Nei_bqdbm"); strColTwo. add ("Nei_bqdmch"); strColTwo. add ("Xiang_mtzh"); strColTwo. add ("Dan_w"); strColTwo. add ("Gong_chshl"); strColTwo. add ("Ding_e"); strColTwo. add ("Ren_gf"); strColTwo. add ("Ji_xf"); strColTwo. add ("Qu_ybm"); strColTwo. add ("Qu_ymch"); newViewTwo = listTwo. views. add ("Default", strColTwo, strQueryTwo, 30, true/** // * Whether paging is supported */, true/** // * whether it is the Default view */, Microsoft. sharePoint. SPViewCollection. SPViewType. grid, false); newViewTwo. title = "internal configuration basics"; newViewTwo. update ();}
The last step is to apply it on the application page (here I only describe the instance situation, and you can choose the specific application) and add an iframe element on the page, you can introduce the URL of the List View.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.