Archive

Posts Tagged ‘moss customisation’

Format Date and Time

Format date and time :

m_CalculatedOutOfOfficeStartDate = outOfOfficeStartDate.ToString("dd/MM/yyyy");
m_CalculatedOutOfOfficeEndDate = outOfOfficeEndDate.ToString("dd/MM/yyyy");

Hope this helps-
Rehman.

Advertisements

Ensure trailing slash

Sometimes you don’t know if you’ll get a trailing slash or not with a web.Url or site.Url. Use the method:

public static string EnsureTrailingSlash(string strUrl)
        {
            if (!strUrl.EndsWith("/", StringComparison.OrdinalIgnoreCase))
            {
                strUrl += "/";
            }
            return strUrl;
        }

Call like this:
SharedUrlUtility.EnsureTrailingSlash(SharedUserProfiles.MySiteHostUrl);

Hope this helps-
Rehman.

Enable Full Toolbar on an XSLT List View Web Part (XsltListViewWebPart) / on a list

July 9, 2012 3 comments

Enabling toolbar for a list programmatically means to enable it on xslt list view web part..Here’s the code:

private void EnableToolbarOnXsltListViewWP(string viewName, string listName, string webUrl)
        {
            using (var spSite = new SPSite(webUrl))
            {
                using (SPWeb web = spSite.OpenWeb())
                {
                    spSite.AllowUnsafeUpdates = true;
                    web.AllowUnsafeUpdates = true;
                    SPList spList = web.Lists[listName];
                    SPView spView = spList.Views[viewName];
                    SPLimitedWebPartManager spLimitedWebPartManager = web.GetLimitedWebPartManager(spView.Url, PersonalizationScope.Shared);
                    foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in spLimitedWebPartManager.WebParts)
                    {
                        if (webPart.GetType().Name.Equals("XsltListViewWebPart") && webPart.Title == Config.ListName_MyCVs)
                        {
                            try
                            {
                                MethodInfo ensureViewMethod = webPart.GetType().GetMethod("EnsureView", BindingFlags.Instance | BindingFlags.NonPublic);
                                object[] ensureViewParams = { };
                                ensureViewMethod.Invoke(webPart, ensureViewParams);
                                FieldInfo viewFieldInfo = webPart.GetType().GetField("view", BindingFlags.NonPublic | BindingFlags.Instance);
                                var view = viewFieldInfo.GetValue(webPart) as SPView;
                                Type[] toolbarMethodParamTypes = { Type.GetType("System.String") };
                                MethodInfo setToolbarTypeMethod = view.GetType().GetMethod("SetToolbarType", BindingFlags.Instance | BindingFlags.NonPublic, null, toolbarMethodParamTypes, null);
                                object[] setToolbarParam = { "ShowToolbar" };
                                setToolbarTypeMethod.Invoke(view, setToolbarParam);
                                view.Update();
                            }
                            catch (Exception ex)
                            {
                                Log.LogError("MyProjName", ex);
                            }
                        }
                    }
                    spSite.AllowUnsafeUpdates = false;
                }
            }
        }

Hope this helps-
Rehman.

Hide Site Actions


<!--Hide Site Actions from readers/visitors -->

<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="EditListItems">

<!-- Site Actions content here... -->

</Sharepoint:SPSecurityTrimmedControl>

Hope this helps-
Rehman.

Update a list view in sharepoint

Update a list view:

public static void UpdateListView(SPWeb web, string listName, string viewName, string fields, string query, int rowLimit, bool isDefault, string scope, bool isTabularView, bool allowInlineEditing)
        {
            try
            {
                web.AllowUnsafeUpdates = true;
                SPList list = web.Lists.TryGetList(listName);

                if (list != null)
                {
                    SPView view = list.Views[viewName];

                    if (view != null)
                    {
                        SPViewFieldCollection fieldColl = view.ViewFields;

                        string[] flds = fields.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                        fieldColl.DeleteAll();

                        foreach (string fld in flds)
                        {
                            fieldColl.Add(fld.Trim());
                        }

                        if (!string.IsNullOrEmpty(scope))
                        {
                            SPViewScope type = SPViewScope.Default;
                            foreach (var value in Enum.GetValues(typeof(SPViewScope)))
                            {
                                if (value.ToString() == scope)
                                {
                                    type = (SPViewScope)value;
                                    break;
                                }
                            }
                            view.Scope = type;
                        }

                        view.DefaultView = isDefault;
                        view.Query = query;
                        view.RowLimit = Convert.ToUInt32(rowLimit);
                        view.TabularView = isTabularView;
                        view.InlineEdit = allowInlineEditing.ToString();
                        view.Update();
                    }
                }
            }
            catch (Exception err)
            {
                Log.LogError(err.Message, err);
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }
        }

Call like this:

SPHelper.UpdateListView(myweb, “Your List Name”, “All Pictures”, “Title,Name,Description,Picture Size,Type”, string.Empty, 100, true, string.Empty, false, false);

“query” if you wish to filter items……
where viewName is an existing view……..

Hope this helps–
Rehman.

Enable BI Center as a subsite

August 4, 2011 Leave a comment

Enabling the following features at a team site collection will allow you to create a BI Centre as a subsite to it.

Site -> Site Actions -> Site Collections Administration -> Site Collection Features -> SharePoint Server Publishing Infrastructure

Site -> Site Settings -> Site collection administration -> Site Collection Features -> PerformancePoint Services Site collection features

Site -> Site Settings -> Site Features -> PerformancePoint Services Site Features

Hope this helps–
Rehman.

Finding SharePoint Release Version – Patch/Update level

It is on the “Manage Servers in this Farm” page in Central Admin:

http://<ServerName:PortNumber>/_admin/FarmServers.aspx

Hope this helps–

Rehman