Moving web part out of SharePoint Designer 2010 to Visual Studio 2010? - sharepoint-2010

I've developed a data form web part in SharePoint Designer 2010. The web part present a filtered view of a list along with edit and insert functions. I want to move the code out to Visual Studio into a solution I have for all our SP enhancements.
I exported the web part to a .webpart file from SP Designer and used that as the .webpart in a visual web part project, but when I deploy the project, the web part from Visual Studio doesn't have any data in it. The same web part deployed from SP Designer does have data in it.
I tried changing the VS web part .cs class to inherit from Microsoft.SharePoint.WebPartPages.DataFormWebPart, but that didn't fix the problem. Here's the .webpart file, any help is appreciated:
<?xml version="1.0" encoding="utf-8"?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="PipelineItemEditor.VisualWebPart1.VisualWebPart1, $SharePoint.Project.AssemblyFullName$" />
<importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
</metaData>
<data>
<properties>
<property name="InitialAsyncDataFetch" type="bool">False</property>
<property name="ChromeType" type="chrometype">TitleOnly</property>
<property name="Title" type="string">My Pipeline Items</property>
<property name="Height" type="string" />
<property name="CacheXslStorage" type="bool">True</property>
<property name="ListDisplayName" type="string" null="true" />
<property name="AllowZoneChange" type="bool">False</property>
<property name="AllowEdit" type="bool">False</property>
<property name="XmlDefinitionLink" type="string" />
<property name="DataFields" type="string" />
<property name="Hidden" type="bool">False</property>
<property name="ListName" type="string" null="true" />
<property name="NoDefaultStyle" type="string">TRUE</property>
<property name="AutoRefresh" type="bool">True</property>
<property name="ViewFlag" type="string">8388621</property>
<property name="Direction" type="direction">NotSet</property>
<property name="AutoRefreshInterval" type="int">60</property>
<property name="AllowConnect" type="bool">False</property>
<property name="Description" type="string" />
<property name="AllowClose" type="bool">False</property>
<property name="ShowWithSampleData" type="bool">False</property>
<property name="ParameterBindings" type="string">
<ParameterBinding Name="dvt_sortdir" Location="Postback;Connection"/>
<ParameterBinding Name="dvt_sortfield" Location="Postback;Connection"/>
<ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>
<ParameterBinding Name="OpenMenuKeyAccessible" Location="Resource(wss,OpenMenuKeyAccessible)"/>
<ParameterBinding Name="open_menu" Location="Resource(wss,open_menu)"/>
<ParameterBinding Name="select_deselect_all" Location="Resource(wss,select_deselect_all)"/>
<ParameterBinding Name="idPresEnabled" Location="Resource(wss,idPresEnabled)"/>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)"/>
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(core,noXinviewofY_DEFAULT)"/>
<ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)"/>
<ParameterBinding Name="MoreAnnouncements" Location="Resource(wss,moreItemsParen)"/>
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
<ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/>
</property>
<property name="Xsl" type="string" null="true" />
<property name="CacheXslTimeOut" type="int">86400</property>
<property name="WebId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">00000000-0000-0000-0000-000000000000</property>
<property name="ListUrl" type="string">Lists/Pipeline</property>
<property name="DataSourceID" type="string" />
<property name="FireInitialRow" type="bool">True</property>
<property name="ManualRefresh" type="bool">False</property>
<property name="ViewFlags" type="Microsoft.SharePoint.SPViewFlags, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Html, TabularView, Hidden, Mobile</property>
<property name="ChromeState" type="chromestate">Normal</property>
<property name="AllowHide" type="bool">False</property>
<property name="PageSize" type="int">-1</property>
<property name="SampleData" type="string" null="true" />
<property name="BaseXsltHashKey" type="string" null="true" />
<property name="AsyncRefresh" type="bool">True</property>
<property name="HelpMode" type="helpmode">Modeless</property>
<property name="ListId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">00000000-0000-0000-0000-000000000000</property>
<property name="DataSourceMode" type="Microsoft.SharePoint.WebControls.SPDataSourceMode, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">List</property>
<property name="AllowMinimize" type="bool">False</property>
<property name="TitleUrl" type="string">/Lists/Pipeline</property>
<property name="CatalogIconImageUrl" type="string" />
<property name="DataSourcesString" type="string" />
<property name="GhostedXslLink" type="string">main.xsl</property>
<property name="PageType" type="Microsoft.SharePoint.PAGETYPE, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">PAGE_NORMALVIEW</property>
<property name="DisplayName" type="string">All Pipeline Items</property>
<property name="UseSQLDataSourcePaging" type="bool">True</property>
<property name="Width" type="string" />
<property name="ExportMode" type="exportmode">All</property>
<property name="XslLink" type="string" null="true" />
<property name="ViewContentTypeId" type="string">0x</property>
<property name="HelpUrl" type="string" />
<property name="XmlDefinition" type="string">
<View Name="{2F369D62-EFD0-4E6F-961D-BA71E4622076}" MobileView="TRUE" Type="HTML" Hidden="TRUE" DisplayName="All Pipeline Items" Url="/SitePages/pipelinetest.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/generic.png">
<Query>
<Where>
<Eq>
<FieldRef Name="Author"/>
<Value Type="Integer">
<UserID/>
</Value>
</Eq>
</Where>
<OrderBy>
<FieldRef Name="Created_x0020_Date" Ascending="FALSE"/>
</OrderBy>
<GroupBy>
</GroupBy>
</Query>
<ViewFields>
<FieldRef Name="Edit"/>
<FieldRef Name="PItemType"/>
<FieldRef Name="PItemText"/>
<FieldRef Name="PItemLink"/>
<FieldRef Name="PItemDirection"/>
<FieldRef Name="PItemPicture"/>
<FieldRef Name="Created"/>
<FieldRef Name="Related_x0020_Tags"/>
</ViewFields>
<RowLimit Paged="TRUE">30</RowLimit>
<Toolbar Type="Standard"/>
<ViewStyle ID="17"/>
</View>
</property>
<property name="Default" type="string">FALSE</property>
<property name="TitleIconImageUrl" type="string" />
<property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
<property name="SelectParameters" type="string" />
</properties>
</data>
</webPart>
</webParts>

Cross posting answer from https://sharepoint.stackexchange.com/questions/24932/moving-web-part-out-of-sharepoint-designer-2010-to-visual-studio-2010/ in the interests of avoiding http://imgs.xkcd.com/comics/wisdom_of_the_ancients.png
Create a new webpart item in an empty SharePoint project.
Copy your exported webpart into the .webpart file
Remove the .cs file
Edit the elements.xml file to set the display name and such for your new web part
Deploy the solution
Load your version of the DFWP web part from the gallery.
In this case you don't need to create a new class, you're just creating a template instance of an existing webpart with pre-set configuration which is set in the .webpart file

Related

How to config activiti.org to work with IBM Domino LDAP groups

I work on integration IBM Domino with activiti.org workflow engine. I need to connect Activiti with Domino LDAP in order to retrive users and groups.
I already can log in with my Domino credentials but I'm not able to resolve user groups. My user is a member of ACTIVITI_ADMINS domino group but he doesn't see activiti-explorer administration menu (the one that default kermit user see). I've made the following modifications in Activiti xml config files. What should I add/rewrite in my config files in order to resolve user groups?
activiti-custom-context.xml
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!--...-->
<property name="configurators">
<list>
<bean class="org.activiti.ldap.LDAPConfigurator">
<!-- Server connection params -->
<property name="server" value="ldap://myDominoLdapServer" />
<property name="port" value="389" />
<property name="user" value="cn=User Ldap, ou=myUnit1, ou=myUnit2, o=myCompany" />
<property name="password" value="myPassword" />
<!-- Query params -->
<property name="baseDn" value="o=myCompany" />
<property name="queryUserByUserId" value="(&(objectClass=inetOrgPerson)(displayname={0}))" />
<property name="queryUserByFullNameLike" value="(&(objectClass=inetOrgPerson)(|({0}=*{1}*)({2}=*{3}*)))" />
<property name="queryGroupsForUser" value="(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))" />
<!-- Attribute config -->
<property name="userIdAttribute" value="displayname" />
<property name="userFirstNameAttribute" value="GivenName" />
<property name="userLastNameAttribute" value="sn" />
<property name="userEmailAttribute" value="mail" />
<property name="groupIdAttribute" value="cn" />
<property name="groupNameAttribute" value="cn" />
</bean>
</list>
</property>
</bean>
activiti-ui-context.xml
<bean name="explorerApp" class="org.activiti.explorer.ExplorerApp" scope="session">
<property name="environment" value="${activiti.ui.environment}" />
<property name="useJavascriptDiagram" value="${activiti.ui.jsdiagram}" />
<property name="i18nManager" ref="i18nManager" />
<property name="viewManager" ref="viewManager" />
<property name="notificationManager" ref="notificationManager" />
<property name="attachmentRendererManager" ref="attachmentRendererManager" />
<property name="formPropertyRendererManager" ref="formPropertyRendererManager" />
<property name="variableRendererManager" ref="variableRendererManager" />
<property name="applicationMainWindow" ref="mainWindow" />
<property name="componentFactories" ref="componentFactories" />
<property name="workflowDefinitionConversionFactory" ref="workflowDefinitionConversionFactory" />
<property name="loginHandler" ref="activitiLoginHandler" />
<property name="simpleWorkflowJsonConverter" ref="simpleWorkflowJsonConverter" />
<property name="adminGroups">
<list>
<value>ACTIVITI_ADMINS</value>
</list>
</property>
<property name="userGroups">
<list>
<value>user</value>
</list>
</property>
</bean>
Your configuration looks right so the problem must have something to do with the LDAP query used to retrieved the groups for the user:
<property name="queryGroupsForUser" value="(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))" />
Is this query returning the ACTIVITI_ADMIN group?
Well, I've found that the baseDN entry was the reason of my problem. I set empty value and Activiti is resolving my group now. The activiti-custom-context.xml file contains the following code:
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!--...-->
<property name="configurators">
<list>
<bean class="org.activiti.ldap.LDAPConfigurator">
<!-- Server connection params -->
<property name="server" value="ldap://myDominoLdapServer" />
<property name="port" value="389" />
<property name="user" value="cn=User Ldap, ou=myUnit1, ou=myUnit2, o=myCompany" />
<property name="password" value="myPassword" />
<!-- Query params -->
<!--MY CHANGE START-->
<property name="baseDn" value="" />
<!--MY CHANGE END-->
<property name="queryUserByUserId" value="(&(objectClass=inetOrgPerson)(displayname={0}))" />
<property name="queryUserByFullNameLike" value="(&(objectClass=inetOrgPerson)(|({0}=*{1}*)({2}=*{3}*)))" />
<property name="queryGroupsForUser" value="(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))" />
<!-- Attribute config -->
<property name="userIdAttribute" value="displayname" />
<property name="userFirstNameAttribute" value="GivenName" />
<property name="userLastNameAttribute" value="sn" />
<property name="userEmailAttribute" value="mail" />
<property name="groupIdAttribute" value="cn" />
<property name="groupNameAttribute" value="cn" />
</bean>
</list>
</property>
</bean>

Session.Get and Session.Load commands ignore filters

I'm using a mapping with a filter.
But when I try to persist my object, it first wants to get a snapshot (because my Id is a string).
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="DomainLayer.General" assembly="DomainLayer">
<class name="Fund" table="OPENA_BriefW" lazy="false">
<id name="Id" column="`BRWNUMMER`" type="string" >
</id>
<property name="Name" column="`BRWNAAM`" type="string" />
<property name="Contact" column="`BRWNAAM2`" type="string" />
<property name="Address" column="`BRWADRES`" type="string" />
<property name="City" column="`BRWSTAD`" type="string" />
<property name="Zip" column="`BRWPOST`" type="string" />
<property name="Phone" column="`BRWTELEFOON`" type="string" />
<property name="Fax" column="`BRWTELEFAX`" type="string" />
<property name="Iban" column="`brw_iban`" type="string" />
<property name="BankAccount" column="`BRWBANKNU`" type="string" />
<property name="Swift" column="`brw_swift`" type="string" />
<property name="ReceiveOffice" column="`BRWONTVKANT`" type="int" />
<property name="RegionDirection" column="`BRWGEWESTDIR`" type="int" />
<many-to-one name="Country" class="DomainLayer.General.CodeDescription" fetch="join" not-found="ignore">
<formula>'ALG'</formula>
<formula>'0'</formula>
<formula>'WG030'</formula>
<column name="`BRWLAND`" />
<formula>:LanguageFilter.Id</formula>
</many-to-one>
</class>
</hibernate-mapping>
As you can see the filter :LanguageFilter.Id is the one causing the troubles. When I do a normal .List() it doesn't cause problems.
But when I persist, it first wants to check if the Fund already exists yes/no. By doing a .Get (with the Id).
Then I get the error can't retrieve snapshot because in my query he doesn't replace :LangaugeFilter.Id with the effective value i set on my session.
I enable the filter on my session like so:
session.EnableFilter("LanguageFilter").SetParameter("Id", 1);
Here's the filter-def mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<filter-def name='LanguageFilter' >
<filter-param name='Id' type='System.Int32' />
</filter-def>
</hibernate-mapping>
This post (comment 4) http://ayende.com/blog/3993/nhibernate-filters says that session.Get and Load ignores filters.
Are there any alternatives, because I need that language to be variable.
Ok, what I did was the following: I didn't use SaveOrPersist, but Save when new and Persist when I had an old one. This didn't execute the extra get.

Could you help me to configure the store procedure in the NHibernate config file?

In my program, i need get a exec a store procedure to decide to get a object from which table, so i need config a stored procedure in my entity nhibernate config file, the config file like below:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Entity.ACC.User, Entity" table="ACC_User" lazy="false">
<id name="Id" column="Id" type="Int32" unsaved-value="0" >
<generator class="increment" />
</id>
<property name="Code" column="Code" type="String" length="50" />
<property name="Password" column="Password" type="String" length="50" />
<property name="FirstName" column="FirstName" type="String" length="50" />
<property name="LastName" column="LastName" type="String" length="50" />
<property name="Type" column="Type" type="Int16" />
<property name="Email" column="Email" type="String" length="50" />
<property name="TelPhone" column="TelPhone" type="String" length="50" />
<property name="MobilePhone" column="MobilePhone" type="String" length="50" />
<property name="Language" column="Language" type="String" length="50" />
<property name="IsActive" column="IsActive" type="Boolean" />
<property name="AccountExpired" column="AccountExpired" type="Boolean" />
<property name="AccountLocked" column="AccountLocked" type="Boolean" />
<property name="PasswordExpired" column="PasswordExpired" type="Boolean" />
<property name="CreateUserId" column="CreateUser" type="Int32" update="false" />
<property name="CreateUserName" column="CreateUserNm" type="String" length="100" update="false" />
<property name="CreateDate" column="CreateDate" type="DateTime" update="false" />
<property name="LastModifyUserId" column="LastModifyUser" type="Int32" />
<property name="LastModifyUserName" column="LastModifyUserNm" type="String" length="100" />
<property name="LastModifyDate" column="LastModifyDate" type="DateTime" />
<sql-insert>
exec USP_User_Insert ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
</sql-insert>
<sql-update>
exec USP_User_Update ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
</sql-update>
<sql-delete>
exec USP_User_Delete ?
</sql-delete>
</class>
<sql-query name="User_Select">
<return class="Entity.ACC,Entity.ACC.User"/>
exec USP_User_Select ?
</sql-query>
</hibernate-mapping>
after i added this query SP in the config file
exec USP_User_Select ?
the program can't run and will throw exception as:
unknown class Entity.ACC, Entity.ACC.User
what should i do let the SP work.
many thanks.
Try changing
return class="Entity.ACC,Entity.ACC.User"
line into
return class="Entity.ACC.User, Entity"

How can I map the same property to differere columns on the same table

<property name="Registration" column="vrn" type="String" length="16" />
<property name="Vin" column="vin" type="String" length="32" />
<property name="EngineCapacity" column="engineCapacityCC" type="Int32" />
<property name="Make" column="make" type="String" length="128" />
<property name="ModelDescription" column="modelDescription" type="String" length="128" />
<property name="ModelCode" column="modelCode" type="String" length="128" />**
<property name="RegistrationDate" column="registrationDate" type="DateTime" />
<property name="Manufacturer" column="manufacturer" type="String" length="128" />
<property name="ManufactureDate" column="manufactureDate" type="DateTime" />
<property name="Range" column="range" type="String" length="128" />**
<property name="DriveType" column="driveType" type="String" length="1" />
<property name="BodyType" column="bodyType" type="String" length="25" />
<property name="EngineType" column="engineType" type="String" length="25" />
<property name="Colour" column="colour" type="String" length="25" />
<property name="IsImported" column="IsImported" type="Boolean" />
<property name="IsLeftHandDrive" column="IsLeftHandDrive" type="Boolean" />
<property name="Range" column="ClientRangeCode" type="String" />**
<property name="ModelCode" column="ClientModelCode" type="String" />**
<property name="IsTaxi" column="IsTaxi" type="Boolean" />
This mapping raise and exception (duplicate property ......)
I need to map ModelCode to both ClientModelCode and modelCode columns
I need to do the same for the property Range
thanks
You can't. It's not possible, nor does it make sense, to have the same property name defined more than once in a class. Your class should have separate properties for ModelCode and ClientModelCode.
Another option is to have private members for ModelCode and ClientModelCode and expose just one through a public ModelCode property.

Many to one mapping problem with NHibernate

Firstly I am relatively new to NHibernate. Got two tables on TaxMapping and Address. A single TaxMapping must have one address and one address can belong to more than one Tax Mapping. They are linked through foreign key
TaxMapping hbm
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ITAPDTO" assembly="ITAPDTO">
<class name="TaxMapping" table="tblTaxMapping">
<id name="Tax_Mapping_ID">
<column name="Tax_Mapping_ID" sql-type="bigint" not-null="true"/>
<generator class="identity" />
</id>
<property name="Tax_ID" />
<property name="Client_Code" />
<property name="NRA_Sub_Account" />
<property column="Domicile" type="String" name="Domicile" length="5" />
<many-to-one name="Address" column="AddressID" cascade="none" not-found="exception" not-null="true" fetch="join" class="ITAPDTO.Address,ITAPDTO" />
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ITAPDTO" assembly="ITAPDTO">
<class name="Address" table="Address">
<id name="AddressID" column="AddressID" type="Int32" unsaved-value="0">
<generator class="identity"/>
</id>
<property column="Client" type="String" name="Client" not-null="true" length="100" />
<property column="Contact" type="String" name="Contact" not-null="true" length="50" />
<property column="Address1" type="String" name="Address1" not-null="true" length="100" />
<property column="Address2" type="String" name="Address2" not-null="true" length="100" />
<property column="Address3" type="String" name="Address3" not-null="true" length="100" />
<property column="City" type="String" name="City" not-null="true" length="50" />
<property column="State" type="String" name="State" not-null="true" length="50" />
<property column="PoBox" type="String" name="PoBox" not-null="true" length="50" />
<property column="PostCode" type="String" name="PostCode" not-null="true" length="20" />
<property column="Country" type="String" name="Country" not-null="true" length="50" />
<property column="InsertedBy" type="String" name="Modified_By" length="20" />
<property column="InsertedOn" type="DateTime" name="Modified_Date" />
<property column="ConfirmedBy" type="String" name="Approved_By" length="20" />
<property column="ConfirmedOn" type="DateTime" name="Approved_Date" />
<property column="Status" type="String" name="Status" />
<property column="IUD" type="String" name="IUD" />
</class>
</hibernate-mapping>
I can pull in the data and bind to grid view with no issue. However when I update the Taxmapping the AddressID for the Address oject is always null event thoughh the other address fields are correctly populated and I dont know why. I currently have a hack in place the pulls the id from the db before I call update but I really shouldn't have to do this. Any thoughts would be welcome
regards
Is this due to cascade being set to "none" on the Taxmapping object's Address property? Try changing it to "save-update". You may also want to read the nhibernate documentation to figure out which cascade setting would be best for your situation, though it sounds like "save-update" would be most appropriate.
In addition to Krazzy's point, you should also check that your sessions are closed and / or flushed appropriately. A long-running session which is never flushed can exhibit similar problems.