Sharepoint DataFormWebPart - sharepoint

Within my DataFormWebPart I have a 'DataSourcesString' property which references and queries a list.
Depending on what page the DataFormWebPart is displayed on I need to be able to configure the query (parameterise the string 'Dispute Resolution' in the code below) within the 'DataSourcesString'.
Does anyone know if there a way to paramterise this by modifying the web part through either the XSL Editor or Paramter Editor?
The web part code snippet relating to the 'DataSourcesString' is below
<property name="DataSourcesString" type="string"><%# Register TagPrefix="sharepoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><sharepoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;/OrderBy&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;Primary&quot;/&gt;&lt;Value Type=&quot;Text&quot;&gt;Dispute Resolution&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;" UseInternalName="True" IncludeHidden="True" ID="datasource1">
Thanks! I appreciate this may not be so clear without screenshots..

You can do this using a QueryString parameter on the DataForm. I'm assuming you're only able to export the webpart. So, export the webpart and save the .webpart to your desktop. Open it and modify it like so:
In your DataSourcesString remove the where clause entirely:
<property name="DataSourcesString" type="string"><%# Register TagPrefix="sharepoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><sharepoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;/View&gt;" UseInternalName="True" IncludeHidden="True" ID="datasource1">
In the <property name="ParameterBindings" type="string"> node, add:
<ParameterBinding Name="MyVariable" Location="QueryString(MyVar)"/>
In the XSL for the webpart itself, find <xsl:param name="dvt_partguid" /> and just below it add:
<xsl:param name="MyVar" />
Finally, find select="/dsQueryResponse/Rows/Row and modify it to be:
select="/dsQueryResponse/Rows/Row[#Primary='$MyVar']
Save the webpart, upload it back, and you should now be able to filter it by adding MyVar=Whatever to your querystring

The only way I found of manipulating parameters at run time was from C# code behind.
Here are the steps required:
Dump your DataFormWebPart code into an ascx control. (or a custom webpart if you wish).
In the code behind of the control, reference your DataFormWebPart via it's ID just like you would to any other user control such as a text box.
Use the DataFormWebPart object to fiddle with its Data Source (if required) and its queries. You can get a handle on all of its parameters.

Related

using rich textbox in Sharepoint 2013

I want to use a rich textbox in Sharepoint 2013 as seen in the figure below. How can I do that?
I have already used the code below.
<%# Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<SharePoint:InputFormTextBox ID="RichTextField1" runat="server" TextMode="MultiLine" RichTextMode="FullHtml" Columns="20" Rows="10"/>
but I could not get what I need. I got a simple multiline textbox with scroll.
Thank you for the answers.
try adding this in
RichText="true"
more or less it would be like this as a sample:
<SharePoint:InputFormTextBox ID="rftDefaultValue"
RichText="true"
RichTextMode="FullHtml" runat="server"
TextMode="MultiLine" Rows="5">
</SharePoint:InputFormTextBox>
also, if you're viewing this using chrome, it would only show as a plain text box, try viewing this using IE :)
Rich Text boxes are an old issue on non IE browsers, if you want to use the abilities of the rich text you will have to use IE.
You can implement other rich text editors on your sharepoint site like tinymce http://joshmccarty.com/2011/06/use-tinymce-as-the-rich-text-editor-in-sharepoint-forms/
I have used this external (cross platform) content editor: http://nicedit.com/index.php and it worked perfectly for me.
And it looks like this:

How can I get a Content Query Web Part to show items from more than one type of list?

I am trying to use a Content Query Web Part to create a "What's New" page in Sharepoint 2010. The goal of this page is to display any documents that have been uploaded in the last 14 days. The trick is that these documents could belong to any number of lists that are defined in any number of list definitions. These are custom list definitions based on custom content types. We do have a base content type that each of our custom content types inherit from. They are also all part of the same content type group. I have determined that it is not possible to use the SP UI to set up the CQWP to return items from multiple list types, since one of the required query fields is list type. So - I'm attempting to use CAML to define this CQWP and this is where I'm having trouble. My end goal is for the CAML to be defined in a site definition (onet.xml file) but I've also not had any luck with uploading a .webpart file from the SP UI. I have found several articles that explain how this should be done but haven't been able to get the suggested solutions to work. This MSDN article tells me it should be possible using the ListsOverride element. This is how the article tells me to do it:
<![CDATA[
<Lists BaseType="0">
</Lists> ]]>
Since I'm looking for Document Libraries I would use a base type of 1 rather than 0.
I have been unable to determine the syntax for what that would actually look like from within the onet.xml file so I thought I'd start with trying to get it uploaded as a .webpart file.
This is what the ListsOverride element looks like:
<property name="ListsOverride" type="string">
<![CDATA[<Lists BaseType="1"></Lists>]]>
</property>
However - as soon as I upload a .webpart file with this in the CAML and add the webpart to a page I break that page in Sharepoint. This is what I get:
Server Error in '/' Application.
Attempted to use an object that has ceased to exist.
Research on that error points me to code that disposes of an object such as SPContext.Current.Web but I don't even have any code at all here. It almost looks like the CQWP has a bug in it. OR - I'm either not formatting that CAML properly or maybe I need to change something in a different element in the CAML?
I am running Sharepoint 2010 SP1 with all the latest patches. (I believe)
I've tried several other formats but without luck.
I tried getting rid of the embedded CDATA tags like this:
<property name="ListsOverride" type="string">
<Lists BaseType="1"></Lists>
</property>
But then Sharepoint won't let me upload the .webpart file. (Invalid .webpart file)
The format with the embedded CDATA tags seems to be the only way it lets me upload the file.
I've tried (just for the sake of narrowing down my issue) to specify specific lists like this:
<property name="ListsOverride" type="string">
<![CDATA[<Lists><List Id="{5a2f79bb-cc82-4171-88ac-65f20e7b5fa8}" /></Lists>]]>
That doesn't break the page but the webpart gives me less than useful error on the page (Unable to display this Web Part)
I'm not 100% sure that I used the appropriate GUID in that attempt. I got it from looking in the server explorer in Visual Studio (Under Lists and Libraries >> Document Libraries >> My List Type. (I got the GUID from the Id property)
I should mention that I am fairly new with Sharepoint development. I would have hoped that something seemingly so core to what Sharepoint does would be much easier than this.
Can someone please point out what I am doing wrong? Maybe I'm going about the whole thing in the wrong way? I appreciate any help that anyone can give me!
I found that the issue was all the "extra" fields that SharePoint had populated.
In my case, I started by configuring the content query web part on the page and then exporting it to get the xml. Then, I put the XML in my onet.xml file of my site definition. That worked fine initially, but as I tried to configure the base types, it did not behave as expected.
If I removed all the additional fields and just used the few fields that I actually needed to configure, then it started to work. In fact, I didn't even need to use the ListsOverride element, since there is a BaseType property that works just fine. It appears that one of the other properties that I was pulling in was really the cause of my issues.
Here's a webpart definition that I used in my onet.xml:
<AllUsersWebPart WebPartZoneID="WebPartZone" WebPartOrder="1">
<![CDATA[
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">Recently Updated Documents</property>
<property name="ChromeType" type="chrometype">TitleOnly</property>
<property name="ChromeState" type="chromestate">Normal</property>
<property name="WebUrl" type="string">~site</property>
<property name="BaseType" type="string">1</property>
<property name="ContentTypeBeginsWithId" type="string">0x0101008B0856395DCD40F99C9B42B6BF92BDDB</property>
<property name="FilterField1" type="string">{28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f}</property>
<property name="FilterType1" type="string">DateTime</property>
<property name="FilterOperator1" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterFieldQueryOperator, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Geq</property>
<property name="FilterDisplayValue1" type="string">-14</property>
<property name="FilterValue1" type="string">-14</property>
<property name="SortBy" type="string">{8c06beca-0777-48f7-91c7-6da68bc07b69}</property>
<property name="SortByFieldType" type="string">DateTime</property>
<property name="SortByDirection" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+SortDirection, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Desc</property>
<property name="ItemXslLink" type="string">~sitecollection/Style Library/DealerPortal/ItemStyle.xsl</property>
<property name="CommonViewFields" type="string">Name,Text;Created,DateTime;Modified,DateTime;Body,Note;DocumentIconImageUrl;OnClickForWebRendering</property>
</properties>
</data>
</webPart>
</webParts>
]]>
</AllUsersWebPart>

WhatsPopularWebPart as delegate control

I want to add the WhatsPopularWebPart as a delegate control. Registered a controlid in the masterpage and created a feature with this XML-manifest:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control ControlAssembly="Microsoft.Office.Server.WebAnalytics.UI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ControlClass="Microsoft.Office.Server.WebAnalytics.Reporting.WhatsPopularWebPart" Id="WebAnalyticsDelegate" >
<Property Name="Title">Most viewed pages</Property>
<Property Name="DateRange">SevenDays</Property>
<Property Name="ItemLimit">6</Property>
</Control>
However, the webpart keeps saying "Loading". I think the callback is not executed. When I look at the HTML, the WebPartId is only zeroes (0000-00000-00 etc.) instead of a valid GUID. Perhaps that is the problem?
I want to add the webpart to every page on the site, therefore using delegate controls.
Hum...
I don't see why it is not working. See this link :
http://blog.brianfarnhill.com/2008/12/08/using-the-delegate-control-to-deploy-a-web-part-through-features/
Maybe it is a problem with This particular webpart : http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/93782f9c-b582-436c-8c66-12349fd752b2
Have you tried with other webpart ?
Solution: ContentPlaceHolder in masterpage and in every page layout a webpart zone in that ContentPlaceHolder. Further in the provisioning of the pagelayout an with the webpart definition of the WhatsPopularWebPart. Problem solved.

Can't display Sharepoint List view webpart

I have a feature that automatically creates some web part pages. I want to display a list in my web part page but I can't get the list to show up. Here is my code in my element.xml file:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Path="PageTemplates" Url="" >
<File Url="Tab3.aspx" Name="Tab3.aspx" Type="Ghostable" >
<View List="Lists/Links"
BaseViewID="0"
WebPartZoneID="Left"
WebPartOrder="0"/>
</File>
</Module>
</Elements>
I know i set up the page correctly because I put the following content editor web part into the page and it shows up:
<AllUsersWebPart WebPartZoneID="Left" WebPartOrder="0">
<![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2"
xmlns:cewp="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
<Title>Some content that you want to provision with the feature</Title>
<FrameType>TitleBarOnly</FrameType>
<cewp:Content>
Hello world.
</cewp:Content>
</WebPart>
]]>
</AllUsersWebPart>
I'm getting the following error in the log: Not enough information to determine a list for module "(null)". Assuming no list for this module.
What am I doing wrong?
More details:
When I use
<View List="Lists/Links"...>
I get no error but nothing shows up on my page. if I enter a bogus list name I get the following error:
Cannot complete this action.
Please try again. at Microsoft.SharePoint.Library.SPRequestInternalClass.EnableModuleFromXml(String bstrFeatureDirectory, String bstrUrl, String bstrXML)
at Microsoft.SharePoint.Library.SPRequest.EnableModuleFromXml(String bstrFeatureDirectory, String bstrUrl, String bstrXML)
I don't believe the previous error I quoted is related to my problem. The error I posted before was
I believe I need to create a ListInstance element in elements.xml file of my feature. I added the following to the top of my file:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance
FeatureId="6A9FB262-8EAD-46C1-814B-7FED72D34EBF"
Id="Links"
Url="Links"
Title="Links"
TemplateType="103"/>
....
I get the following error:
Failed to find a suitable list for tag in module for file 'Tab3.aspx' given List attribute 'Links'.
Where is that list located? You may need to specify the web name, probably by Guid. If 'lists' is the web then once you reference this you only need the list name, i.e. 'links'
My solution was to create the page in Sharepoint Designer and then copy the code into the feature aspx page.

How to add a custom built webpart to a custom view aspx page in list definition project

I have developed a list definition project and created a custom view aspx page to be the default view of the list. I would now like to add a custom webpart to be displayed in the custom view aspx page. Any ideas of how it can be done?
You can use a feature receiver and manage the addition of web parts during feature activation. Here is a bit of a stub to help get you started.
In the feature activated method call code similar to the following:
// Add web parts to the .aspx page that was provisioned
SPFile page = site.GetFile(<<page url>>);
Hashtable hashWebPartsOnPage = new Hashtable();
using (SPLimitedWebPartManager mgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
try
{
// First, let's clear the existing web parts off of the form
foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in mgr.WebParts)
{
hashWebPartsOnPage.Add(webPart.ID, webPart);
}
foreach (string webPartName in hashWebPartsOnPage.Keys)
{
System.Web.UI.WebControls.WebParts.WebPart webPart = hashWebPartsOnPage[webPartName] as System.Web.UI.WebControls.WebParts.WebPart;
mgr.DeleteWebPart(webPart);
}
// Add Part to the proper Zone
MyWebPart myWebPart = new MyWebPart();
//set web part properties
mgr.AddWebPart(myWebPart, "FullPage", 1);
}
finally
{
mgr.Web.Dispose();
}
}
page.Update();
On SharePoint 2010 you can add a custom webpart or SharePoint WebPart in the same view definition inside the Schema.xml of the List definition (I'm not talking about List instance).
Although isn't directly explained by MSDN, and if you look at the View Schema you can't see a '<WebParts>' definition, you can actually do something like this:
<View BaseViewID="7" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:CILSS_defaultView" DefaultView="TRUE" MobileView="FALSE" MobileDefaultView="FALSE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="CI_Projects.aspx">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main_cilss.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ViewFields>
<FieldRef Name="Attachments"></FieldRef>
<FieldRef Name="LinkTitle"></FieldRef>
<FieldRef Name="CILSS_ProjectDescription"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="LinkTitle" Ascending="TRUE"></FieldRef>
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
<WebParts>
<AllUsersWebPart WebPartZoneID="Main" WebPartOrder="2">
<![CDATA[<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>Default Home Webpart</Title>
<FrameType>None</FrameType>
<Description>Use for formatted text, tables, and images.</Description>
<IsIncluded>true</IsIncluded>
<ZoneID>Left</ZoneID>
<PartOrder>0</PartOrder>
<FrameState>Normal</FrameState>
<Height />
<Width />
<AllowRemove>true</AllowRemove>
<AllowZoneChange>true</AllowZoneChange>
<AllowMinimize>true</AllowMinimize>
<AllowConnect>true</AllowConnect>
<AllowEdit>true</AllowEdit>
<AllowHide>true</AllowHide>
<IsVisible>true</IsVisible>
<DetailLink />
<HelpLink />
<HelpMode>Modeless</HelpMode>
<Dir>Default</Dir>
<PartImageSmall />
<MissingAssembly>Cannot import this Web Part.</MissingAssembly>
<PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
<IsIncludedFilter />
<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
<ContentLink xmlns="" />
<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
<Value><div>Create and view Project documents:</div>
<br/></Value></Content>
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>]]>
</AllUsersWebPart>
</WebParts>
</View>
This view definition includes a Content Editor Webpart in the list view called 'CI_Projects.aspx'
Remember to assign the WebPartZoneId and assign a BaseViewID different from the default views included in the List definition.
The webpart will provisioned on every List you will create with this List Definition. (obviously only on the named view.aspx you define).
Well i would like to access the list definition view page which i don't think will be accessible using the above site.GetFile() method. Any other options you think we can use to achieve it. I have tried the following steps:
Copy the OOB “ViewPage.aspx” and place it in the same folder as “CustomViewPage.aspx”
Create the custom web part which shows the items of the view with your custom approach.
Create a feature to provision the “CustomViewpage.aspx” along with your custom web part.
Create a custom list definition. In the schema.xml file of the definition for all the views mention the “SetupPath” to refer your “CustomViewPage.aspx”. With this step all the views mentioned in the list definition will use the “CustomViewPage.aspx” to create the view pages and as well all the views which you create after the creation of the list will use the “customViewPage.aspx” as the base page to create the view pages.
Step 1:
Just copy the OOB “ViewPage.aspx” and place it in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\Pages folder as “CustomViewPage.aspx”
Step 2:
Create the custom web part which shows the items of the view with your custom approach. Basically use the GetViewfromUrl(“Lists//”) method to get the view and then retrieve the items in the web part. The code snippet for the custom web part looks like follows :
SPList list = SPContext.Current.List;
String strViewName =
SPView view = SPContext.Current.Web.GetViewFromUrl("Lists/list/ "+strViewName);
SPListItemCollection listItems = list.GetItems(view);
.
.
.
.
After getting the list items then do your custom approach of displaying the items.
Build the web part DLL and place it in the GAC.
Step 3:
Create a feature to provision the “CustomViewPage.aspx” along with your custom web part. By activating this feature the “Customviewpage.aspx” will be embedded with your custom web part. The elements manifest file content looks like follows :
<File Url="Pages/CustomViewPage.aspx" Type="Ghostable">
<AllUsersWebPart WebPartZoneID="Main" WebPartOrder="1">
<![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
<Assembly>CustomWebpartforView, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e3483ddc8b0d437a</Assembly>
<TypeName> CustomWebpartforView.MyCustomview</TypeName>
<FrameType>None</FrameType>
<IsVisible>true</IsVisible>
<Title>Custom Web part for View</Title>
</WebPart>
]]>
</AllUsersWebPart>
</File>
This step gives me error for the source file path which i modified by giving the Path attribute in the File Tag
Step 4:
Now the base custom view page is available along with the web part. Now how to integrate the custom view page with the list definition. Create a custom List definition and for all the views defined in the schema mention the “SetupPath” to use the “CustomViewPage.aspx”. Now the custom view page will be used as the base view page for all the views defined in the list definition and as well the views created later also will be using the “CustomViewpage.aspx” as the base page. The sample snippet for declaring the views inside the schema.xml is as follows :
Install and activate the feature of your custom list definition.
Now with all these steps, when you create a list based on this custom list definition then all the views created will be using the “CustomViewPage.aspx” to create the view pages and your custom web part will be rendered instead of the OOB dataformwebpart. The views which you will be creating after the creation of the List (Through UI, Through Object Model) will also use the “CustomViewpage.aspx” as the base page to create view pages.
For some reason i am still unable to see the CustomViewPage.aspx with my custom webpart. Am i missing somthing or there is something missing in this article.

Resources