Sharing the experience search

Search sharing-the-experience.blogspot.com
Showing posts with label webpart. Show all posts
Showing posts with label webpart. Show all posts

Friday, November 16, 2012

ListFormWebPart: ViewFlag attribute. Or How to make a form default?


List Item Forms (*.aspx file). When uploading it to the list’s SP folder and only if there is ListFormWebPart control in the file, SP adds the file to the Forms collection for the list with the following characteristics:

FormType property:
4 – Display
6 – Edit
8 – New
For values see more detailed here:

ViewFlag property – if absent then is not Default

((int)Microsoft.SharePoint.SPViewFlags.Default) == 1048576



Monday, August 20, 2012

SharePoint UX: Styling and Branding. Design implementation

Previous related posts:



Last day Kyle Schaeffer in his Styling and Branding class dove deeper into jQuery and how to use it to enhance User Experience in SharePoint portal.

Kyle said it clearly and easy to remember:


CSS is all about presentation

HTML is all about structure

JavaScript is all about behavior. (Jquery should enhance the interface but your basic structure should be functional even without jQuery)

Remember this and you design will be easy to manage.



The quick signposts to implement it in SharePoint:
Picture Library -> Content Query WP -> Item Style -> jQuery Script with jQuery Cycle Plugin

P.S. Item style is to change the presentation of the data

Friday, April 22, 2011

Module feature: ListViewWebPart how to hide the toolbar?

 I have a module feature for the default page with ListViewWebPart on it:

<View Type="CALENDAR" List="$Resources:core,lists_Folder;/DiscussionReview" BaseViewID="2" WebPartZoneID="BottomLeft" WebPartOrder="1" Scope="Recursive">
        <![CDATA[
            <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
            <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
            <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>
            <Title>At-Risk Discussions</Title>
          <AllowMinimize>false</AllowMinimize>
          <AllowHide>false</AllowHide>
          <AllowRemove>false</AllowRemove>                    
            </WebPart>
            ]]>
      </View>
I want to hide the toolbar on that webpart.

I can do it through UI (Edit Page-> (If the webpart in the zone - I can access to the web part properties)-> chose a webpart and click edit -> Modify Shared web part->Toolbar Type->No Toolbar):

But I want to make this change in my SharePoint project and make it deploybale.
The Toolbar Type is not a property of the webpart, but the view itself.
SPView.ToolbarType Property (MSDN)

In this case, I can change this Toolbar Type property in the view in schema.xml:


<Toolbar Type="None">

P.S. To my delight - this change got propagated to already created list without any complications.

Thursday, January 27, 2011

File provisioning: a hard-coded list id replacement

Howdy!
Today's topic might really help you in your SharePoint life. I will present to you a  technique to work with SPD workflow and page provisioning to make them portable from one environment to another. Not delaying any further - I will show you  real world examples with it's issue:
 Example #1. I have created SPD (SharePoint Designer ) workflow and want to export it and import to the another site created from the same site template (different enviroment: Dev, Qc, Staging).
 Issue: The exported wf holds hard-coded list id value
 Example #2. I have created a XSLT webpart and put it in a module <file> element. This feature should work on every site created from the site template to which this feature is belong to.
Issue: The xslt webpart has a hard-coded ListId.

Ok, I think it's convincing enough to read on to find a solution for described situations.
Here is our custom approach:
   We created a feature which we call SiteProvisioning. It consists of 2 elements:
1. A custom class: SiteProvisioning.cs which set as ReceiverClass for the feature:
<Feature Id="{4FA2AC90-321A-4d4c-B587-CE6D4A5B90FA}"
         Title="SiteProvisioning"
         Description=""
         Version="1.0.0.0"
         Scope="Web"
         Hidden="FALSE"
         DefaultResourceFile="core"
         ReceiverAssembly="Custom.SharePoint.Case, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a4607a0133bbaeb2"
         ReceiverClass="Custom.SharePoint.Case.SiteDefinition.SiteProvisioning"

         xmlns="http://schemas.microsoft.com/sharepoint/">
  <ActivationDependencies>
    <ActivationDependency FeatureId="43DA1A6A-0759-4093-B84D-9593555BC037"/>
  </ActivationDependencies>
( I will explain this element later)
  <ElementManifests>
    <ElementFile Location="SiteProvisioning.xml" />
  </ElementManifests>
</Feature>

2. And a file:
 <ElementManifests>
    <ElementFile Location="SiteProvisioning.xml" />
  </ElementManifests>
SiteProvisioning file is a list of elements which are originally have a hard-coded value and related list title;
<SiteSettings>
  <FixupFiles>
    <FixupFile DataViewInZone="true" DeleteWebPartsOnDeactivation="true" RelativePath="Lists/Discussion/DiscussionView.aspx" />
    <FixupFile DataViewInZone="true" DeleteOnDeactivation="true" RelativePath="default.aspx" />
    <FixupFile DataViewOutZone="true" DeleteOnDeactivation="true" RelativePath="default.aspx" />
  </FixupFiles>
  <ListInstances>
    <ListInstance Id="fd482aa7-9511-4b0f-abeb-79030bb681ca" Title="Case" />
    <ListInstance Id="85ac067e-e536-46f3-9a7b-032016cd032d" Title="Case Review Meeting" />
    <ListInstance Id="cde441a0-b34f-4f19-ba47-52b0b5c8d49e" Title="Action Items" />
    <ListInstance Id="dd764ce9-aa7a-41aa-aa2f-28841aee3356" Title="Claims" />
    <ListInstance Id="9b811048-cbd5-4e41-b526-703f1ddc3fae" Title="Disciplinary Actions" />
    <ListInstance Id="A8949622-30DB-4CE6-A6A6-B674DED51355" Title="Involved People" Web="/apps/systems/cases/" />
    <ListInstance Id="cbe513fb-ef61-45aa-9162-23398b8a4011" Title="Reports" />
    <ListInstance Id="4DF356F2-90CF-4D76-9B38-1B17F3B3D6E9" Title="Tasks" />
  </ListInstances>
</SiteSettings>

Every time we put a xslt web part in the module file, we need to be sure that we found a hard-coded value in it and added it to the SiteProvisioning also we need to put a file where we should replace this id during siteprovisioning.

The guy who will be in charge of the replacement is a  SiteProvisioning class
Here is an essence of it:

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            if (properties == null)
            {
                return;
            }

            SPWeb web = properties.Feature.Parent as SPWeb;         
            string filePath = this.GetProvisioinerFilePath(properties.Definition);

            var sz = new XmlSerializer(typeof(SiteSettings));
            SiteSettings settings = null;
            if (File.Exists(filePath)) {
                using (var sr = File.OpenRead(filePath)) {
                    try {
                        settings = sz.Deserialize(sr) as SiteSettings;
                    } catch { }
                }
            }

            if (settings != null) {
                this.RestoreDataViewInZone(web, settings);
                this.RestoreDataViewOutZone(web, settings);           
            }

            this.OnActivated(properties);
        }
  private void RestoreDataViewInZone(SPWeb web, SiteSettings settings)
        {
            if (settings.FixupFiles == null)
                return;

            foreach (var xFixupFile in settings.FixupFiles.Where(i => i.DataViewInZone))
            {
                var relativePath = xFixupFile.RelativePath;
                if (string.IsNullOrEmpty(relativePath))
                {
                    continue;
                }

                SPFile file = web.GetFile(relativePath);
                if (file == null)
                {
                    continue;
                }

                SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
                SPLimitedWebPartCollection pageWebParts = manager.WebParts;
                if (pageWebParts == null)
                {
                    continue;
                }

                foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in pageWebParts)
                {
                    if (((webPart is DataFormWebPart) && (((DataFormWebPart)webPart).ParameterBindings != null)))
                    {
                        this.SubstituteGuidInZone(web, manager, webPart as DataFormWebPart, settings);
                        this.SubstituteIDInZone(web, manager, webPart, settings);
                    }
                    else
                    {
                        this.SubstituteIDInZone(web, manager, webPart, settings);
                    }
                }
                // http://msdn.microsoft.com/en-us/library/aa973248.aspx
                //
                //  Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager
                //  The SPLimitedWebPartManager class contains a reference to an internal SPWeb object that must be disposed.
              
                manager.Web.Dispose();
            }
        }

 private void SubstituteGuidInZone(SPWeb web, SPLimitedWebPartManager manager, DataFormWebPart dataForm, SiteSettings settings)
        {
            if (settings.ListInstances == null)
            {
                return;
            }

            foreach (var xListInstance in settings.ListInstances)
            {
                if (xListInstance.Id == null || xListInstance.Title == null) {
                    return;
                }

                SPList list = null;
                try
                {
                    if (string.IsNullOrEmpty(xListInstance.Web))
                    {
                        list = web.Lists[xListInstance.Title];
                    }
                    else
                    {
                        using (SPWeb listWeb = web.Site.OpenWeb(xListInstance.Web))
                        {
                            list = listWeb.Lists[xListInstance.Title];
                        }
                    }
                }
                catch (ArgumentException)
                {
                    continue;
                }

                if (list == null)
                {
                    continue;
                }
                string newId = list.ID.ToString();


                dataForm.ListName = newId;
                dataForm.ParameterBindings = Regex.Replace(dataForm.ParameterBindings, xListInstance.Id, newId, RegexOptions.IgnoreCase);
                dataForm.DataSourcesString = Regex.Replace(dataForm.DataSourcesString, xListInstance.Id, newId, RegexOptions.IgnoreCase);
                dataForm.Xsl = Regex.Replace(dataForm.Xsl, xListInstance.Id, newId, RegexOptions.IgnoreCase);

                manager.SaveChanges(dataForm);
            }
        }

     private void SubstituteGuidInZone(SPWeb web, SPLimitedWebPartManager manager, DataFormWebPart dataForm, SiteSettings settings)
        {
            if (settings.ListInstances == null)
            {
                return;
            }

            foreach (var xListInstance in settings.ListInstances)
            {
                if (xListInstance.Id == null || xListInstance.Title == null) {
                    return;
                }

                SPList list = null;
                try
                {
                    if (string.IsNullOrEmpty(xListInstance.Web))
                    {
                        list = web.Lists[xListInstance.Title];
                    }
                    else
                    {
                        using (SPWeb listWeb = web.Site.OpenWeb(xListInstance.Web))
                        {
                            list = listWeb.Lists[xListInstance.Title];
                        }
                    }
                }
                catch (ArgumentException)
                {
                    continue;
                }

                if (list == null)
                {
                    continue;
                }
                string newId = list.ID.ToString();


                dataForm.ListName = newId;
                dataForm.ParameterBindings = Regex.Replace(dataForm.ParameterBindings, xListInstance.Id, newId, RegexOptions.IgnoreCase);
                dataForm.DataSourcesString = Regex.Replace(dataForm.DataSourcesString, xListInstance.Id, newId, RegexOptions.IgnoreCase);
                dataForm.Xsl = Regex.Replace(dataForm.Xsl, xListInstance.Id, newId, RegexOptions.IgnoreCase);

                manager.SaveChanges(dataForm);
            }
        }

Thursday, June 24, 2010

Closed web part - how to manage

Sometimes someone who has a right but not clear understanding what he\she is doing can easily close public web part on the page.
 Maybe you were wondering how to handle this situation and how to find any missing, closed web part.
The answer is simple - add to the page url where you want to manage web parts  the param : ?contents=1
Here we go - the management will appear!

P.S. Every time I discover that somebody closed the web part I don't remember how to restore it!!! As reminder for myself: Go to the page where the web part should be restored and click Edit Page , Add webpart -> Gallery->Closed webparts