I'm looking to add a new field onto my NewForm.aspx, EditForm.aspx and DispForm.aspx pages in Sharepoint Designer 2007. I've managed to add a new textbox webpart and have edited the Common Textbox Tasks to make the Data Field my new field (Contacts..)
But how do I edit Edit.aspx and DispForm.aspx to display this new field?
I've looked around already answered questions on the site but I haven't run across what I'm really looking for -- sorry if I missed it!
Thanks!
Shannon
It doesn't count as "development", but wouldn't creating a new List column, Site Column or Content Type add this additional field to all your list forms just fine? How does this not work in your particular case?
You have to use SharePoint Designer to access the site and edit those aspx (in the 'Forms' subfolder of the folder named after the list)
You are probably going about this the wrong way. You should not need to change the edit and new forms for a list just because you want a new field. You do need to add the field to the underlying list and rely on the code in the forms to display the field correctly.
IN SPD choose the Table tab on the far right, then Select a row, then you can Insert Above or Insert Below, then you can add your new field.
New item, edit, and display forms aren't attached to lists so much as they attached to content types. If you can't use InfoPath or Designer to set these up, what you do is the following:
Create the form in question as an application page. For whatever reason, SharePoint application pages won't render on-screen, so to get an idea of what I'm looking at I generally make them in a visual web part or separate ASP application first, then copy and paste the ASP/HTML over, then delete the original.
In the case of edit and display forms, SP will pass you a query string with the ID in it. I capture the item in question thusly:
NameValueCollection nvQueryString = Page.Request.QueryString;
taskID = Convert.ToInt32(nvQueryString["ID"]);
ViewState["TaskID"] = taskID;
SPWeb thisWeb = SPContext.Current.Web;
SPList taskList = thisWeb.Lists["Job Request approval tasks"];
SPListItem taskItem = taskList.GetItemById(taskID);
After adding on whatever it is you need to add on, you do need to add logic to the .cs page or a separate class that actually edits/adds the item in question. Probably pretty obvious...
From here you have three options: either create an event receiver that points the editformURL/displayformURL/newformURL of the content type in question to your application page, create a brand new content type and add the URL for your application page in its XML definition, or add it manually via Powershell.
Related
I'm looking into an issue with a large SharePoint 2010 list (68 fields) where when the user tries to add new fields to the list, they do not show up.
I can successfully make changes to old fields, but every new field I add doesn't show up. However, they DO show up as an available field in SharePoint Designer and on the List Properties page.
I've tried enabling Content Type Management and making changes, (a common solution) but that didn't seem to help.
Anyone see this before?
While I don't know what caused this, the solution was to use SP Designer to create a new New Item Form. When I did that, the new custom columns appeared.
NOTE: Simply recreating the New form was not enough. I had to create a New Item form with a different name and set it as the Default for that type.
I am trying to create a Page Layout, that should have a lookup field. Lookup field should always get populated with a list's items.
This list will exist in all subsites, so whereever I create this page, list should get populated with listitems from current site.
I tried using site column lookup field, but it always point to list under top site and not the current site.
Any suggestion on how to make it work or better alternative? Thanks!
Let me know if I can provide more info.
The most straightforward solution I can think of is using a cross site lookup column and creating a seperate fields for each subsite. However, you will need to create and use different Page Layouts for each subsite.
You can use http://sp2010filteredlookup.codeplex.com/ for cross site lookups.
Solution 1 - Use http://sp2010filteredlookup.codeplex.com/
Use filtered lookup solution. So let's say you have your custom Page Layout and custom Page Content Type.
Every time you create new subsite, you should remember go to Pages list settings and edit Page Content Type by adding cross site lookup (with the same field "internal name").
So you still have one Page Layout (and one Content Type). But for each Pages library instance, Content Type contains diff fields (but with the same Internal Name). It will allow you run CAML queries and other things needed without any problems.
Solution 2 - develop custom sharepoint field type.
In edit mode, control will render "dropdown list" and populate data from list instance that is on current subsite. In the field settings you can have relative list url.
Solution 3 - hidden text field / js snippet solution
Page Content Type can contain hidden text field (it can contains selected field value in json format for example). Develop js snippet that will handle all the logic (rendering in edit/view mode, saving etc) and put it on Page Layout (aspx).
I would suggest to use solution #1 or #2.
I have a list with the fields: Title, Client, Project, Description.
There is a view for analysts with the fields visible: Title, Project, Description.
All is fine so far as the analysts work with their views and not with the lists. But when they need to modify the records clicking on Edit, they see and able to modify the 'Client' field too.
How to prevent 'Client' field to be available for editing by the group? is there a way in WSS or I need to look for 3rd party list components?
All fields have a set of properties that determine their visibility in forms, such as "ShowInNewForm", "ShowInEditForm", and "ShowInDisplayForm". There's also some for the file dialog, the list settings page, and a few other places, but that's getting past it. Short answer, yes, you can make the field not show up in the edit form with WSS without needing any 3rd party components.
If you need a field that cannot be seen in the Edit Form by anyone (that is, no one should be able to have it in their form), then you need to modify "ShowInEditForm" to be true. This can't be modified directly through the SharePoint UI, but it is extremely simple using the object model.
If you need certain people to edit it at some point through the SharePoint UI, then you'll instead have to create a custom edit form. That's a bit more complex, so I'll hold off on providing that instruction unless you state you need to go down that route (or someone else passes by this answer and requests it). Nevertheless, it is fully possible with WSS 3.0.
EDIT
If you know already know how to insert inline C# code into an ASPX page, you can perform this very simply using SharePoint Designer. First, follow the instructions from this article, especially make sure you don't delete the default list form web part. Now, in the custom list form you added, make it include every field which anyone will be capable of editing. The last step is to make the form hide those fields for certain people. Let's default them to Visible=false, and flip this switch if the user is allowed them. You can do this either by checking if the current user is part of specified groups, or by checking if the user has a certain permission level only held by people of those groups. You'll basically write some code like the following, I'll use checking for a specified group as the example.
using (SPWeb web = this.Web)
{
SPUser currUser = web.CurrentUser;
string[] listOfGroups = { "Group1Name", "Group2Name", "Group3Name" };
foreach (string groupName in listOfGroups)
{
if (currUser.Groups.Contains(groupName))
{
//Repeat this for each Control, refer to them by their ID. For example, this is for a control with the ID txtTitle.
txtTitle.Visible = true;
}
}
}
If you don't know inline code, you'll have to write a custom ASPX page with a code-behind. Copy EditForm.aspx into a new file - you should do this after setting up a Custom List Form as per the article. You could also build a new ASPX page from scratch, but make sure you include all of the necessary Content placeholders for SharePoint pages. Now, the page currently inherits from Microsoft.SharePoint.WebPartPages.WebPartPage. We need to create custom code that inherits from that class, and change the page to inherit that new custom code instead. In the custom code, override one of the OnLoad or OnInit methods, and include your check for the user's permissions there as detailed earlier. Compile the code, deploy it to your SharePoint server, and it should be functional.
If you want to set fields hidden or display them in new form or edit form page of the list...
Go to the list settings.
In Advanced Settings, enable "Allow management of content types"
By doing so, you will get a List name Link on the List Setting Page.
Open the link and select the fields that you want to hide or uhide using add or remove option.
After saving this, again disable "Allow management of content types" in Advanced Setting...
Thats it :)))
I think I'm going mad - this seemed like an easy thing to do but I can't find any info on it at all.
I have created a Custom List and added 4 columns to it. Created By and Modified By are already in the list but hidden from the view.
I want to add a Date Modified column (which is a built in field) to this Custom List. How do I do this programmatically?
Are you trying to add the column to the list or to a view? The Date Modified column should be added to the list by default. To add it to the view (i.e. so it shows up when you navigate to the list) you can use code similar to the following:
using (SPWeb web = new SPSite("http://intranet/").OpenWeb())
{
SPList customList = web.Lists["CustomList"];
SPView defaultView = customList.DefaultView;
defaultView.ViewFields.Add("Modified");
defaultView.Update();
}
With sharepoint sometimes you must do ugly things... stuff you would not want your children know when they grow up.
Here is a pitifull solution:
- you create a DateTime field just like any other.
- you create a workflow when data changes, workflow starts, updates that your custom modified field and then stops.
ANYWAY, I know it is possible to show the default Modified field, perhaps you wanna go in that direction a little bit more.
I'm working on a SharePoint publishing site and I want to "log" all the changes made by users in a SharePoint list.
Some searches on the web guided me to the EventReceiver.
But my EventReceiver must be generic and attached to all lists in the site collection. The "log list" has several columns like the name of the list in which the event occurred, the name of the modified item, its old value and its new value.
Can someone guides me on how to achieve this?
There's already a provided answer for you on StackOverflow, hurrayy!!
It sounds possible. Create a class that inherits from SPItemEventReceiver and override ItemUpdating. You can use the following code to get the list:
using (SPWeb web = properties.OpenWeb())
{
SPList list = web.Lists[properties.ListId];
}
You can then use list to grab the list's title and URL. Next, compare each DictionaryEntry entry in properties.AfterProperties to the corresponding value in properties.ListItem to get your differences. Then save it to your log list. The trick would be automatically attaching your Event Receiver to each newly created list. Perhaps a timer job would work.
That said...
Before trying any of that, go to your site collection's Site Settings. Under Site Collection Administration, click Site collection audit settings. Under Specify the Document and Item events to audit, check Editing items. Only go with a custom solution if that does not give you what you need.
Would Version history not achieve the same functionality?
You can see what fields were changed by who and when. Though you would have to look at a list by list basis.
You can also access the version history information via the object model if you want to generate reports web part.
Otherwise using Janis Veinbergs link on how to attach a event handler to all lists and Rich Bennema method of getting the values from the updated item in a generic way, though I would use ItemUpdated as you don’t want to change the data that was updated only copy it to another location so there is no need to catch the data before it is submitted to the SharePoint database