One of the things I found out the hard way while programming event handlers in sharepoint is that you have to wrap your update() or delete() functions with the disableeventfiring function individually, for example:
this will work:
base.DisableEventFiring();
item.update();
base.EnableEventFiring();
this will NOT work:
base.DisableEventFiring();
item.update();
item.delete();
base.EnableEventFiring();
So the moral of the story is, only do one event triggering action at a time, do not try to do 2 or more within one wrapper.
Ok here is how I add or remove or copy permissions to a list item in sharepoint:
| 1 |
if (properties.ListTitle.Equals(“Document Library”)) |
| 2 |
{ |
| 3 |
using (SPWeb objWeb = properties.OpenWeb()) |
| 4 |
{ |
| 5 |
SPListItem d_item = properties.ListItem; //this is the one I want to copy permission from
|
| 6 |
SPRoleAssignmentCollection roles = d_item.RoleAssignments; |
| 7 |
SPListItem item = myFile.Item; //this is the one I want to copy permission to |
| 8 |
item.BreakRoleInheritance(true); //you must set this to true or it wouldn’t work
|
| 9 |
while (item.RoleAssignments.Count > 0) |
| 10 |
{ |
| 11 |
item.RoleAssignments.Remove(0); |
| 12 |
} |
| 13 |
foreach (SPRoleAssignment role in roles) |
| 14 |
{ |
| 15 |
item.RoleAssignments.Add(role); |
| 16 |
} |
| 17 |
base.DisableEventFiring(); |
| 18 |
item.Update(); |
| 19 |
base.EnableEventFiring(); |
| 20 |
} |
| 21 |
} |
I needed to customize the item edit / display / new form to remove some fields from the form. In SPD you can not convert the edit form to XSLT dataview. What you have to do is:
1. Hide the default form: Select the ListFormWebPart, right click and select web part properties. Go to layout and check hidden.
2. Insert your custom form: Click on an empty area so nothing is selected. Then go to Insert->Sharepoint controls->Custom List form, then select the list you are modifying and select the type of form. Now you can modify or delete any field!
To Add/Remove/Manage columns in sharepoint designer(SPD), first open up the site in SPD then open up the view’s aspx file. In design mode, right click on the DataFormWebPart and select “convert to XLST data view”.
Now you should have a “Common data view tasks” popup, if not, just click on the arrow to the right. You could then select “edit columns”. Now you will be able to add/remove/manage columns in SPD! Save the file when you done and your sharepoint site will be automatically updated with the new columns.
Today I found out the hard way that SharePoint doesn’t like the function Int32.Parse. I spent several hours trying to debug my code, then finally come to the conclusion that by using Int32.Parse to convert a int to string, it mysteriously prevents execution of everything that follows this line (although this compiles perfectly in VS2008).
The SharePoint correct way to convert int to string is to use the function Convert.ToInt32(myString), btw Convert is also faster than Parse, so I recommend everyone to stop using Parse and use Convert instead even if it is not sharepoint.
This is a tool written by Stuart Preston to enable us to mass upload files, folders and sub-folders into our sharepoint document library. The tool will automatically create the folders in sharepoint. There is no limit on the number of documents you could upload.
Download SPBulkUpload
How to use:
1. Extract the zip file, this is actually a Visual Studios project with source code.
2. To start using the tool, copy the Conchango.Sharepoint.Utilities.BulkUpload.exe file from /bin/Debug folder to your C:\ root folder and rename it to something shorter like “spbulk.exe”.
3. Open up command prompt (Start->Run->cmd)
4. type: C: to go to your C:\ root
5. type: spbulk “c:\source folder” “http://webapp/site/target/document_library”
(replace the source folder and destination with your actual folder and site url)
6. Wait for the tool to finish.
1. Open up the .aspx file responsible for displaying the document list in Sharepoint Designer, in my case it is called AllItems.aspx
2. Select the WebPartPages:ListViewWebPart control. (It is the place where rows of document are listed)
3. Right-click on it, Convert to XSLT Data View
4. Go into the code and find the line that says:
<xsl:value-of select="ddwrt:UrlBaseName(string(@LinkFilename))" />
5. Add this to the end of the line:
.<xsl:value-of select="@File_x0020_Type" />
6. Save
Caution: after editing the file with sharepoint designer, you wouldn’t be able to edit it with anything else except maybe Visual Studio