Sharepoint default list item detail view - sharepoint

I have a webpart that renders random list items (from any list and list type) in a specified format. I want the items that are being displayed in the webpart to link to their ListItem detail views. However, I don't see a property on the list itself that would tell me what view is the default DETAIL view for the list (ie. blog list detail is Post.aspx). Does this come from the list definition? How would I get that information programmatically? I'm trying to avoid hard-coding any list information based on list type.

Have a look at SPList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url.
I think this is what you're looking for. You'll need to append the the SPListItem.ID on the querystring so that it knows which list item to display.
using (SPWeb myWeb = GetMyWeb()) // GetMyWeb gets a reference to a SPWeb object
{
SPList myList = GetMyList(myWeb); // GetMyList gets a reference to a SPList object
SPListItem myItem = GetMyListItem(myList); // GetMyListItem gets a reference to a SPListItem object
string url = String.Format("{0}/{1}?ID={2}",
myWeb.Url,
myList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url,
myItem.ID);
}
It's also a good practice to append &Source=/url/to/current/page to the querystring so that users will be redirected back to the page they left when they click the Cancel/Close buttons on the Edit or Display forms.

Related

Pulling items from Allitems view using caml query

I have two views. One is Dashboard view, and next one is AllItems View. Here, Dashboard is the Default View. But i have to pull items from Allitems view using CAML Query. Can anybody tell me how to achieve this.
That is pretty basic.
Assuming you have a SPList object, you just specify the View property:
SPList list = website.Lists["Listname"];
SPView queryView = list.View["AllItems"];
queryView.Query = " ... "
queryView.Update();
There are already a lot of resources available convering this:
https://sharepoint.stackexchange.com/questions/39474/filtering-items-in-a-view-using-a-caml-query
https://sharepoint.stackexchange.com/questions/42612/how-to-set-caml-query-for-special-view
https://msdn.microsoft.com/en-us/library/ms434064(v=office.14).aspx

Infopath SharePoint Document Libraries

I need to display a list of document libraries a user has permission to on an infopath form for a workflow. I can build my list of libraries just fine but I can not for the life of me figure out how to populate (in anyway) the infopath form with the list of libraries and allow the user to somehow say "yes" or "no" to each (checkbox is ideal but I'll take anything at this point).
Basically I just need to figure out how to add a list of items for yes/no to a user in the loading event so I can take that information and do something with it.
I tend to use a repeating table with two columns, one containing a checkbox and one a label. Group these together properly in a schema then you can pop some code behind in to iterate through your list of libraries and pop nodes onto the end of this repeating table pre populated.
Here is an example that sets a label inside a repeating table on an InfoPath form:
XPathNavigator xmlDoc = MainDataSource.CreateNavigator();
XPathNavigator xmlItem = xmlDoc.SelectSingleNode("/my:MyForm/my:MyRepeatingGrp", this.NamespaceManager);
foreach (XmlNode libraryNode in documentLibraries)
{
XPathNavigator newItem = xmlItem.Clone();
XPathNavigator navText = newItem.SelectSingleNode("/my:MyLabel", this.NamespaceManager);
navText.SetValue(libraryNode.Attributes["LibraryName"].Value);
xmlItem.InsertAfter(newItem);
}
xmlItem.DeleteSelf();

Weird SPListItem URL when adding a new announcement

When I add a new item in a default Announcement list using the GUI the new item looks just as I would expect, showing the title of the item in the breadcrumb. However when adding the new item through the object model:
SPList theList = web.Lists["announcement"];
SPListItem theitem = theList.Add();
theitem["Title"] = "this is the title";
theitem.Update();
then the breadcrumb will display something like
WebTitle.ListTitle.34_.000, which I believe to be the itemID and versionnumber of the item.
A search give this but I would like to know the root cause and possible how to avoid the issue.
The issue has been resolved. Actually the list in question was a discussion list, not a announcement list ( why it was then named "announcement" is a big mystery),
Since a discussion is actually a thread container and the threads within the container, I had to call SPUtility.CreateNewDiscussion rather then list.Add.

Person & Group custom field type sharepoint

I have created a custom field type as it is there in sharepoint OOTB, the difference is only that the end user does not need to check the name i.e I have replaced it with DropDownList. The dropdownlist suggest the no. of users available in the web site for that I have created a FieldClass which inherits from SPFieldUser and a FieldControlClass which inherits from UserField. It is working fine in all conditions i.e when I create a List or Document Libarary it shows me the DropDownList
with respective users after saying OK it creates an item for me. I have overriden a Value property in FieldControlClass as follows,
public override object Value
{
get
{
SPUserCollection userscollection = rootWeb.SiteUsers;
//ddlInfoBox is a DropDownList to which I have Binded the collection of users in the form of string
SPUser user = userscollection.Web.EnsureUser(this.ddlInfoBox.SelectedValue);
SPFieldUserValue userval = new SPFieldUserValue(user.ParentWeb, user.ID, user.LoginName);
return userval;
}
set
{
SPFieldUserValue userval = (SPFieldUserValue) this.ItemFieldValue;
this.ddlInfoBox.SelectedValue = userval.Lookupvalue; //Here look up value is nothing but a Login name e.g In-Wai-Svr2\tjagtap
}
}
Due to above property the Custom Field's Value for this current ListItem will be stored as SPFieldUserValue e.g 27#;In-Wai-Svr2\tjagtap.
The main problem is here, when this particular ListItem is shown in the list page views e.g on AllItems.aspx or the custom view pages associated with it, it shows the
number as 27 as a FieldValue insted of HyperLink with text as "In-Wai-Svr2\tjagtap" and PostBackURL as "/_layouts/userdisp.aspx?ID=27".
When I edit this Item it makes the respective value selected in the dropdownlist, also while viewing this item i.e on DispForm.aspx it also shows the hyperlink. I have
acheived it by writting a custom logic in createchildcontrol() method i.e by using ControlMode if it is New or Edit then fill the dropdown list, if it is Display then get the ItemFieldValue Type Cast it into SPFieldUserValue and get corresponding lookupid and value for making the URL and showing Text of the HyperLink.
I have spent a lot of time on searching and bringing the HyperLink as the user name with navigation insted of UserID (27) as a string on the list view pages e.g AllItem.aspx but to no avail, then after a lot of research I found that there might be a way of achieving such kind of functionality by using field type definition xml file where there is a provision to define a DisplayPatteren as you wish by specifying the html code. But here is a problem How can I get the UserID (27) with respective UserName e.g In-Wai-Svr2\tjagtap inorder to make an anchor tag like In-Wai-Svr2\tjagtap which will solve my problem. I have hard coded this anchor tag within the Default case statement of a switch under DisplayPatteren but it shows me the field value on AllItems.aspx as
In-Wai-Svr2\tjagtap27 i.e the value defined in xml file is concatenating with the string value (27).
Please help me to resolve the above mentioned 2 issue. I am really in need of solving this problem ASAP.
Thanks & Regards,
Tejas Jagtap
Have u tried to override the GetFieldValueAsHtml() method in the the custom field class or maybe the RenderFieldForDisplay() method in the custom field control class.
Can you use the DisplayPattern CAML from the User field type?

SharePoint Form Library: Programmatically or Stsadm command to change content type to custom form template

I have a custom site definition which includes a form library. I have a form template created in InfoPath. Through SharePoint features I can deploy everything except I cannot figure out how to change the default form for the form library to point to the form I created in InfoPath. I have a feature which deploys the form just great but I have to manually go into advanced settings on the form library, allow content type management, change the default content type to the template, and remove the default content type.
Any ideas on how to do this programmatically or through stsadm would be greatly appreciated!
Colby Africa
Here is some code I have used to do set the content types for a list.
void AddContentTypes(SPWeb web)
{
//get a reference to content types previously installed
SPContentType CompanyAContentPage = web.AvailableContentTypes["CompanyA Content Page"];
SPContentType CompanyAWelcomePage = web.AvailableContentTypes["CompanyA Welcome Page"];
//get list to mess with
SPList spList = web.Lists["Pages"];
//enable management of content types
spList.ContentTypesEnabled = true;
//get the content types added to the list (different from the web ones)
SPContentType newCompanyAPageContentType = spList.ContentTypes.Add(CompanyAContentPage);
SPContentType newCompanyAWelcomePageContentType = spList.ContentTypes.Add(CompanyAWelcomePage);
//update list
spList.Update();
//get a list of content types for the "new" drop down on the list
List<SPContentType> contentTypeList = new List<SPContentType>();
contentTypeList.Add(newCompanyAPageContentType);
contentTypeList.Add(newCompanyAWelcomePageContentType);
//set the content types for the "new" drop down list
spList.RootFolder.UniqueContentTypeOrder = contentTypeList;
spList.RootFolder.Update();
}
Not exactly the same as your problem, but I hope it helps.

Resources