Showing posts with label sharepoint. Show all posts
Showing posts with label sharepoint. Show all posts

Thursday, January 20, 2011

Redirecting back to the view post page instead to default.aspx on publish/cancel button click

Clicking on the edit button on the top right corner of the post content of post view page (Posts.aspx?Id=PostId) navigates to the edit post page. And from the edit post page, once the publish or cancel button is clicked the system redirects the page to the default page of the blog site, ie the default.aspx page. But in some cases this behavior may be confusing to user because normally the user might expecting to return back to the post which he was viewing, ie the post view page where he clicked the edit button.

To do this change we can either do it by modifying the site definition file of the blog template or by opening the Posts.aspx file in Sharepoint Designer. Here we will discuss on how to change this at the site definition level so that it changes this behavior globally.

Firstly, we need to open the blog site definition folder under the 12 Hive,

Image 01 

then we need to go to Lists\Posts folder, in this folder we can find an file named schema.xml, this xml file is schema definition for the posts list, that means the xml definitions about the list such as fields, content types, views etc.

Here we need to modify the view of the posts list, when added as the listviewwebpart in the page posts.aspx, and that can be found under, xml tree node path,
<List .... >
<MetaData>
    <Views>
        <View BaseViewID="7" FreeForm="TRUE" Type="HTML">

Image 02 

Be careful while modifying this xml file, a minor typo may even break the site definition, so keep a back up at first [:-)]

Now search for the section which actually add the edit button link html, ie. search for the TD which add the button, (<TD align="right" class="ms-blogedit">)
Here the button is being added based on the permissions, i.e. we need to modify it in 3 places. So if you go through the HTML sections, the above mentioned TD is being added 3 times, for each section of that HTML
<![CDATA[]]>,
replace the node which has default.aspx text enclosed in HTML (<HTML><![CDATA[%2Fdefault.aspx]]></HTML>)
with the below 2 nodes,
<HTML><![CDATA[/$Resources:core,lists_Folder;/$Resources:core,blogpost_Folder;/Post.aspx?ID=]]></HTML><Column Name="ID" URLEncode="TRUE" />

By adding the above 2 nodes, we mean that we need to replace the default.aspx with the url of post.aspx with ID value being the currently edited post id.
So before the change the node will be like this,
Image 03

and after change

Image 04

Do an IISRESET to reload the sitedefinitions, and then refresh the posts.aspx page to see the change.

P.S: If you wish to alter the behavior specific to a single web only, if requirement is for a fresh web then you can create a new site definition based on blog, so the default blogs remain intact. For modifying few of the existing blogs, the option is to make this change in posts.aspx page by opening that in Sharepoint designer for that web.

Tuesday, September 21, 2010

Apply Filter on Category Field in Content Query Webpart which displays Posts

Recently I came across an issue on applying filter on a content query webpart(CQWP) which was configured to show list items from Posts list. The filter which needs to be applied was against the Category column of the post so that the webpart shows on posts of that category.

So I choose,

image but when I click Apply button, the webpart threw an error.

image

To solve this error, and to apply the filter properly we need to add an additional filter property on the .webpart file. Export the webpart to hard disk, open the .webpart file in any text editing tool, find the property tag with name “AdditionalFilterFields

image

Replace that with

image

Actually we need to add additional filter field PostCategory, which is the internal column name of the category field of posts.

Now save the .webpart file and import this to the webpart page, after this if we go to the modify webpart, and in the additional filter column we will find the PostCategory displayed,

image

Choose that PostCategory, and apply the filter logic,

image Click OK or Apply button to make the changes.

That’s it, now the CQWP will show the posts where category contains Category 1,

image

Friday, August 20, 2010

Modifying the ItemStyle.xsl causes the Summary Links Webpart to crash.

Scenario : An additional presentation template was added for rendering the Content Query Webpart which used the shared parameter value SiteUrl to build the link. The template was good enough and the content query webpart worked perfectly. But interestingly soon after this change, the Summary Links webpart stopped working. It showed this message "Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator."

While checking the ULS (Unified Logging Service) Log files under in 12 Hive\Logs folder, the error logged was this,
“w3wp.exe (0x015C)  0x06B0    Windows SharePoint Services       Web Parts                         89a1    Monitorable    Error while executing web part: System.Xml.Xsl.XslLoadException: The variable or parameter 'SiteUrl' is either not defined or it is out of scope. An error occurred at http://servername/Style Library/XSL Style Sheets/ItemStyle.xsl(471,4).     at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)     at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)     at Microsoft.SharePoint.WebPartPages.DataFormWebPart.GetXslCompiledTransform()     at Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTransform() “

What was happening was that while transforming the Summary Links webpart (which didn't used the new XSL template added) it kept crashing since it couldn't find the variable SiteUrl.

Solution: If you are willing to unghost the xsl files then use sharepoint designer to open the SummaryLinkMain.xsl (which can be found under Style Library\XSL Style Sheets folder in designer) or if you are worried about unghosting then find the SummaryLinkMain.xsl under the 12 Hive folder, TEMPLATE\FEATURES\PublishingResources.
Open the file SummaryLinkMain.xsl in any text editor, and find the top section where the <xsl:param ... /> tags can be seen.
Append the following tag just below any existing <xsl:param ... /> tag
<xsl:param name="SiteUrl" />

Save the file and Refresh the file if you have unghosted using Sharepoint Designer, else do an IISRESET and then refresh the page.

Now the Summary Links webpart is back to working without any issues.

More Information: The MSDN document has mentioned how the xsl files are related.

http://msdn.microsoft.com/en-us/library/ms551040.aspx

Tuesday, August 17, 2010

Microsoft Active Accessibility in MOSS

Today while navigating across the tabs in browser which had some of my MOSS websites open, a new menu link came into my notice, see the screen shot below.

image

To be frank initially I thought it might be a menu from my browser, but out of curiosity I did a search on internet and this is what I found,

“On an MOSS 2007 technologies-based site, most user interface (UI) elements, such as links, form controls, and buttons, are designed to use Microsoft Active Accessibility (MSAA). MSAA enables people with disabilities to interact with content by using assistive technologies such as screen readers, which are devices that provide a synthesized speech or Braille description of what a blind or low-vision user is unable to see on a computer screen or Web site. Proper MSAA names are given on all editable controls, links, and buttons.” – Quoted from Andrew Woodward

Thanks to Andrew Woodward (MVP, Moderator) of social.msdn.microsoft.com, and the link is http://social.msdn.microsoft.com/Forums/en-US/sharepointaccessibility/thread/b4f541e0-ece1-4cbc-9e61-bdc74553180c
and his detail link in which he has explained in detail what is this all about.. http://www.21apps.co.uk/sharepoint/sharepoint-accessibility-is-moss-2007-accessible/

Basically it allows the user with disabilities to access the web content, in MOSS it changes the way the Drop down menus in list behaves, instead of the html dropdown it pops up another window with the options and some of the enhanced controls such as rich text boxes with normal text boxes.

Normal Behavior –> image                          

With accessibility mode on –> ScreenClip000006

To enable this Turn On more accessible link, just refresh page and press on tab key (repeat the tab press if the menu doesn't shows up)

I have been working with Sharepoint for a pretty long time but still the product is surprising and giving me fresh feel everyday. It was a fresh thing for me to learn like some of you just did .. :-)

LiveJournal Tags: ,,

Wednesday, August 4, 2010

Checking permission of SPUser who is member of an Active Directory Group which is added to an SPGroup

Consider the following scenario, an AD group is added to an SPGroup. We need to check the permission of a user which is a member of that ADgroup when he logs in to the sharepoint application. Basically the SPUser.Roles or SPGroup.Roles is accessible only if the logged in user is having permission to access the roles information. In this the user wont be an administrator so the Roles information cannot be accessed and it will throw an AccessDenied Exception. So one way to check current user's permission inside elevated code block is to Open the SPWeb, get all the SPGroups of web then check for the group member is an domain group or not, if domain group then recursively loop to find the user based on current user's login name and if found then check for group's role information. But the above code will definitely keep processor busy and too much coding is required and chances of unwanted recursive loop execution is also there. On thinking how to solve this in an effecient way, the SPGroup.ContainsCurrentUser property came into help. For this, firstly out side the elevation block gets the SPGroups of CurrentWeb and check whether current user is a member of each group, if member then add those group information into a temporary collection, I am using List<KeyValuePair>(int, string) to store the collection of SPGroup's ID and Title. And then inside the elevated code block, loop through the elevated SPWeb's groups and check whether the iterated group belongs in the collection of KeyValue which we loaded earlier. If the group is in temporary collection then check that SPGroup's Roles, since it is in elevated code block the Roles information can be fetched without any exception. The code block can be found below,

private bool CheckWhetherCurrentUserHaveFullControl()
{   
    bool hasFullControlPermission = false;
    ////Gets all the groups to which user is having access
    List<KeyValuePair<int, string>> groupsToWhichUserHasAccess = new List<KeyValuePair<int, string>>();
    foreach (SPGroup spGroup in SPContext.Current.Web.Groups)
    {
        if (spGroup.ContainsCurrentUser)
        {
            groupsToWhichUserHasAccess.Add(new KeyValuePair<int, string>(spGroup.ID, spGroup.Name));
        }
    }
    Guid spWebGuid = SPContext.Current.Web.ID;
    Guid spSiteGuid = SPContext.Current.Site.ID;
    int id = SPContext.Current.Web.CurrentUser.ID;
    SPSecurity.RunWithElevatedPrivileges(() =>
    {
        using (SPSite spSite = new SPSite(spSiteGuid))
        {
            using (SPWeb spWeb = spSite.OpenWeb(spWebGuid))
            {
                SPGroupCollection spGroupCollection = spWeb.Groups;

                foreach (SPGroup spGroup in spGroupCollection)
                {
                    var checkPermission = from groupToWhichUserHasAccess in groupsToWhichUserHasAccess
                                          where groupToWhichUserHasAccess.Key == spGroup.ID
                                          select groupToWhichUserHasAccess;

                    if (checkPermission.Any())
                    {
                        foreach (SPRole spRole in spGroup.Roles)
                        {
                            if (spRole.Name.ToUpper().Equals("FULL CONTROL"))
                            {
                                hasFullControlPermission = true;

                                break;
                            }
                        }
                    }
                }
            }
        }
    });
    return hasFullControlPermission;
}

By the above method we can meet the objective and without writing much lines of code and unwanted recursive call against Active Directory objects.

Cheers !!!

Friday, July 2, 2010

Displaying Flash Content in SPGridView

Hi all, while playing around with SPGridView, the power creating a new class by inheriting the SPBoundField to render any Html element gave me the thought of displaying Adobe flash content on Sharepoint SPGridView. The .swf files are stored in an Sharepoint document library, the SPGridView added to an webpart or a custom aspx renders the information from that document library. The document library is used as the flash content store. Even though I am not that familiar with Flash rendering and tags, I managed to get that the <object> tag is the used to show flash content. The object tag has some specified properties and parameters which in turn renders the flash object in the browser. Basically the SPBoundField can be inherited and by overriding ChildControlDataBinding and the custom html element can be rendered. One of the parameters of ChildControlDataBinding provides the dataItem which has the current SPListItem of the row. So the SPListItem properties can be accessed and from that the swf file’s serverRelativeUrl is fetched.

The SPFlashField class is given below,

public class SPFlashField : SPBoundField
{
    protected override void ChildControlDataBinding(System.Web.UI.Control childControl, object dataItem, System.ComponentModel.MemberDescriptor dataFieldPropertyDescriptor)
    {
        PlaceHolder placeHolder = (PlaceHolder)childControl;
        SPDataSourceViewResultItem spDataSourceViewResultItem = dataItem as SPDataSourceViewResultItem;
        Microsoft.SharePoint.SPListItem spListItem = spDataSourceViewResultItem.ResultItem as Microsoft.SharePoint.SPListItem;
        string fileUrl = spListItem.File.ServerRelativeUrl;
        LiteralControl literalControl = new LiteralControl();
        literalControl.Text = "&nbsp;";
        //Only if the file is a flash file
        if (fileUrl.ToLower().Contains(".swf"))
        {
            literalControl.Text = this.GetFlashObjectHtml(fileUrl, spListItem.Name, "250", "538");
        }
        placeHolder.Controls.Add(literalControl);    
    }

    protected override System.Web.UI.Control GetChildControlInstance()
    {
       return new PlaceHolder();
    }

    private string GetFlashObjectHtml(string swfFileUrl, string swfName, string height, string width)
    {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.Append("&lt;object height='" + height + "' width='" + width + "' name='" + swfName + "' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' classid='clsid:" + new Guid().ToString() + "&gt;");
        stringBuilder.Append("&lt;param value='" + swfFileUrl + "' name='movie'&gt;");
        stringBuilder.Append("&lt;param value='high' name='quality'&gt;");
        stringBuilder.Append("&lt;param value='transparent' name='wmode'&gt;");
        stringBuilder.Append("&lt;param value='always' name='allowscriptaccess'&gt;");
        stringBuilder.Append("&lt;embed height='" + height + "' width='" + width + "' allowscriptaccess='always' type='application/x-shockwave-flash' flashvars='strm=stream3' bgcolor='#ffffff' quality='high' src='" + swfFileUrl + "' name='" + swfName + "' wmode='transparent' id='" + swfName + "'&gt;");
        stringBuilder.Append("&lt;/object&gt;");
        return stringBuilder.ToString();
    }
}

Note: Replace &gt; with > and &lt; with <, my live editor didn’t allowed me to copy paste that code snippet ;-)

The final output is like shown below,

ScreenClip000001

The function GetFlashObjectHtml can be also used to render flash in a webpart, or even in a custom SPField.

Tuesday, May 18, 2010

Removing the export menu items of the report view webpart in sharepoint Integration mode

Open the configuration file "rsreportserver.config" located at "C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer\rsreportserver.config". The config file is an Xml file which acts as the configuration for the current report services installation. From the nodes locate the sub node element named . Xml file with report data - <Extension Name="XML" Type="Microsoft.ReportingServices.Rendering.XmlDataRenderer.XmlDataReport,Microsoft.ReportingServices.XmlRendering"/> CSV (Comma delimited) - <Extension Name="CSV" Type="Microsoft.ReportingServices.Rendering.CsvRenderer.CsvReport,Microsoft.ReportingServices.CsvRendering"/> TIFF file - <Extension Name="IMAGE" Type="Microsoft.ReportingServices.Rendering.ImageRenderer.ImageReport,Microsoft.ReportingServices.ImageRendering"/> Acrobat (PDF) file - <Extension Name="PDF" Type="Microsoft.ReportingServices.Rendering.ImageRenderer.PdfReport,Microsoft.ReportingServices.ImageRendering"/> Web archive - <Extension Name="MHTML" Type="Microsoft.ReportingServices.Rendering.HtmlRenderer.MHtmlRenderingExtension,Microsoft.ReportingServices.HtmlRendering"/> Excel - <Extension Name="EXCEL" Type="Microsoft.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer,Microsoft.ReportingServices.ExcelRendering"/> Just add the attribute Visible="false" to the Extension element which has to be hidden in the Export option, say you want to hide Xml then < Name="XML" Type="Microsoft.ReportingServices.Rendering.XmlDataRenderer.XmlDataReport,Microsoft.ReportingServices.XmlRendering" Visible="false"/> Go back to the webpart page and then do a page refresh and you will find that the export option is not rendered. P.S. Please make sure that you don't do the comment out or remove the Extension node unless you are sure that type of rendering will not be required, else it will shown an rendering error.

Saturday, September 12, 2009

Sharepoint WebService Deployment Routine

Follow the steps for deploying ASP.Net Webservices to Sharepoint environment.
1. Run the ASP.Net Webservice from Visual Studio (Hit F5).
2. Copy the URL from the browser.
3. Open Visual Studio Command Prompt.
4. Go any Folder using DOS Command
5. Type the Command DISCO http://servername:portnumber/WebServiceName.asmx ( URL Copied in Step 2)
6. This will generate the discovery (.disco) file and the WebService Definition (.wsdl) file to the Current Folder.
7. Rename the .disco and .wsdl to WebServiceNameDisco.aspx and WebServiceNameWsdl.aspx
8. Replace the header of the (files mentioned in Step 7) .aspx files to use ASPX page header tags
<%@ Page Language="C#" Inherits="System.Web.UI.Page" %> <%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint.Utilities" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
9. Replace the webservice url references inside the file to use Server tag which builds the Dynamic WebUrl at request time.
Remove the localhost link to the wsdl and asmx uri with
<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + "?wsdl"),Response.Output); %> for wsdl
and <% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> respectively
10. Open the .asmx file in some text editing tool (notepad for eg.) and replace the CodeBehind to use the Respective class and the Dll name space.
<%@ WebService Language="C#" Class="NameSpace.ClassName, NameSpace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dllkeytoken" %>
where NameSpace is your dll namespace, ClassName is the WebService class name and dllkeytoken is the public ket token of dll. 11. Copy WebServiceName.asmx, WebServiceNameDisco.aspx and WebServiceNameWsdl.aspx to ISAPI Folder in the 12 Hive.
12. Test the WebService Request by typing the WebService Request as follows, http://sharepointurl/_vti_bin/WebServiceName.asmx.

Note: The WebService can be debugged in Visual Studio (if dll Deployed is in Debug Mode) by attaching it to the w3wp.exe process.

Monday, August 24, 2009

Setting up Sharepoint Server Search to index pdf content and to show PDF Icon

  1. Decide the image to be shown for the pdf doc icon and copy it to 12\TEMPLATE\IMAGES (Normally icpdf.gif file)
  2. Open DOCICON.XML which is located in folder 12\TEMPLATE\XML
    1. Under the node <byextension> add the below statement.
      1. <mapping key="pdf" value="imageFileName.gif">
      2. imageFileName.gif is the name of the gif file copied above
      3. Save the XML file.
  3. Go to Sharepoint Central Admin -> Shared Services
    1. Click on file types
      1. Click on the new file type to add the pdf file type. Click ok to add it to the list. And verify that the file extension is populated.
  4. Stop the IIS
  5. Install the Adobe IFilter which can be downloaded from internet (ifilter60.exe).
  6. After successful installation of Abode IFilter restart IIS.
  7. Reset Crawled content (SharedServices -> Search Settings) this is required since it may not re-crawl the older sites even in Full Crawl.
  8. Now need to add the Name column to do this follow the steps
    1. Go to Search Settings -> Metadata property mappings
    2. Add a new Mapped Property for FileLeafRef. Click on the Add Mapping, in the seach text box enter keyword fileleafref and click on find to filter the Select Crawled property to ows_FileLeafRef(Text). Click on ows_FileLeafRef(Text) in the list box to select it and Click OK. Enter the propery name as “Name”
    3. Click Ok to Save it.
    4. Make sure that the newly added property is populated in the list
  9. After Resetting go to Content Sources and Crawl Schedules
  10. Apply a Full Crawl
  11. Wait for the crawl to complete.
  12. Once the crawl is completed the pdf document matching the search criteria will be shown in search results.

Wednesday, August 12, 2009

Using Excel Service hosted using Sharepoint in .Net Application (C#)

An Excel Sheet is created to do a calculation of ADD.
Cell$G$155 is set to function SUM of the values on Cell$G$145 and Cell$G$150 (Instead of the Cell and Row No, the Defined a Name to the Cell and that can be used)
The Above excel is published to an Excel enabled Sharepoint Library.
The above library url has to be set as trusted Url in the Sharepoint Central Admin Excel Services Settings.
Below is how that published excel can be used for calculation from another application (webpart, Console or anyother .Net Application) using C#.
Add the Web Service Reference of the ExcelService first to the application.

ExcelService oExcelServ = new ExcelService();
oExcelServ.Url = SPContext.Current.Web.Url + "/_vti_bin/ExcelService.asmx";
oExcelServ.Credentials = System.Net.CredentialCache.DefaultCredentials;

Status[] Status = null;
String SessionID = null;
string pathWorkBook = @"http://servername/LibraryName/excelFile.xlsx";
SessionID = oExcelServ.OpenWorkbook(pathWorkBook, "en-US", "en-US", out Status);
int val1, val2;

//EXCELSHEETNAME à The Name of the Sheet in the .xlsx file which is published.
//EXCELSHEETNAME!$G$145 à SheetName!$CellAlphabet$RowNo
Status = oExcelServ.SetCellA1(SessionID, "EXCELSHEETNAME", "EXCELSHEETNAME!$G$145", val1);
Status = oExcelServ.SetCellA1(SessionID, "EXCELSHEETNAME", "EXCELSHEETNAME!$G$150", val2);

//Execute the CalculateWorkbook function to trigger Calculation
Status = oExcelServ.CalculateWorkbook(SessionID, CalculateType.CalculateFull);
object result = null;

// Read the result back from the Cell.
result = oExcelServ.GetCellA1(SessionID, "EXCELSHEETNAME", "EXCELSHEETNAME!$G$155", true, out Status);

Tuesday, May 6, 2008

About Blog

Hi All, This is for sharing technical information for the world. More updates will be coming soon ....