Showing posts with label web part. Show all posts
Showing posts with label web part. Show all posts

Tuesday, October 6, 2009

SharePoint list view web part wildcard search

I know, most of the SharePoint developers are looking for this. As everyone knows we can do partial search on data view web part by passing a parameter to it and by using the expression "contains" we can implement partial search on a field or column. But, when you come to list view web part you can't pass the parameters [There is no support for list view web part like web part parameters] and no way we can implement the partial keyword search. Today I have spent time on it to solve this problem with the help of my colleague Durga and found a wonderful way. This is giving really wonderful result and doing wild card search even on very big document libraries fast. Below are the steps I followed to solve this. [I will post detailed post on it with screen shots and nice explanation soon in this blog.]

  • Created an ASPX web part page in a SharePoint site.
  • Added two web parts to the page. One is for content editor web part and another is for list view web part of a SharePoint library or list.
  • Now, open the page in IE browser and add a text box, button to the content query web part.
  • Written simple logic to button click event of the button and reload the page with the below formatted url. The url should be of the format

"you aspx page url?FilterName=FieldName&FilterMultiValue=*valuefromtextbox*".

  • In above url, we are using two key value pairs to solve our problem.
  • First one is FilterName: which is for in which field of the list view we need to search the value. For example the value may be Title, ID etc…
  • Second one is the FilterMultiValue: Which is for what is the value we need to search. i.e. keyword. So, here you can pass multiple values too separated by semi-colon ';'.
  • So, example url should like this
  • http://mosssite/pages/listviewcustomwildcardsearch.aspx?FilterName=Title&FilterMultiValue=*prav
  • Now the above url will search all the records in the given list view for the keyword "prav". So, wherever it exists in the given field name it will return all records.

Then how it is working?
Generally, If you research on query strings for a list view web part, it expects some query strings to filter and sort. I am SharePoint developer and got to know the two query strings which SharePoint list view web part uses for filtering. FilterName and FilterMultiValue. So, with that my research continued and tried long time with so many operators like %, single quotes, double quotes etc… in the value of the FilterMultiValue. Finally, I tried with * character before and end of the keyword, there I succeeded. Example: *prav* to FilterMultiValue.

  • That’s it…. Working simply great.
  • With that, You are done implementing the wild card search in a column in list view web part.

Happy by doing SharePoint customization. I know, this will solve so many problems to SharePoint dev’s.  Isn’t it? Please let me know if you have any questions, issues and write your valuable feedback and comments.

Will post more descriptive explanation of this post with screenshots soon in this blog. Follow me!!!

Monday, April 27, 2009

MOSS My Calendar web part login problem for different accounts.

Introduction
When i work with my calendar web part in SharePoint i got lot of questions and things happend. I configured every thing correctly in My Calendar web part. i.e. Mail server address, Mailbox.
But, when i open the page which contains calendar web part, it prompts for user name and password of SharePoint site and another for the Calendar login . i.e. login page of OWA application. If i provide the credentials it will work very fine.

Now the problem starts. If the same application is trying to access by another users, other than me then they always failed to login to my calendar web part. This is because, in mailbox i given my mail account, when others try to access the web part, it won't work at all. What they need at that time is they will edit the web part, and will change the mail box entry to their own email address. But this is not possible for all users because all users don't have access to edit page/web part.

My Calendar web part is not working for multiple users in SharePoint 2007. When you add the web part on a page, which mail entry you given in the Mail box that account only can login. I will tell you the reason behind it. My calender web part is developed only for the purpose of showing their calendar events on the my site page. My site usually have access to edit/delete etc for current logged in user, so he will see the content belongs to him. But as per my requirements i want to use the calendar on the site other than the my site pages.

Solution
To solve the above mentioned problem, i created a custom web part to work for any logged in user. You can get this code and build it, add the appsetting variables in the web.cofig and deploy it to your site, You can get the deploy instructions of web part in MSDN.

Web.Config changes:
We need to provide 2 inputs to the web part.
1. Site Url.
2. Exchange Server Url.

Requirements:
We have setup a job [Usually we will setup while installing SharePoint and configuring the SSP] in your SharePoint server Shared services Provider [SSP], to pull user accounts from the Active Directory to Sharepoint profile database. Because below code gets the emailid automatically from the user profile database depending on the logged in user. And places that emailid in Mail Box entry of the my calendar web part.

Usually, when we configure the Profile import, we will give source and configure the schedule too. i.e. Every day night or every week etc… it pulls data from given source [ex: Active directory] to profile database.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Portal.WebControls;
using Microsoft.SharePoint.Portal.Topology;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Portal.UserProfiles;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;namespace MyCalendarWebPart
{
[Guid("15241046-2128-4a1d-b6d5-24c8a67c4d28")]
public class MyCalendarWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
private OWACalendarPart wpCalendar;
HtmlGenericControl litMsg = null;
HtmlGenericControl roundedCorner;

protected override void CreateChildControls()
{
wpCalendar = new OWACalendarPart();
litMsg = new HtmlGenericControl();
roundedCorner = new HtmlGenericControl();
roundedCorner.InnerHtml = “”;

Controls.Add(configureCalendar());
Controls.Add(litMsg);
Controls.Add(roundedCorner);

base.CreateChildControls();
}

private OWACalendarPart configureCalendar()
{
try
{
//Connect to the portal and get the portal context.
TopologyManager topology = new TopologyManager();
PortalSite portal = topology.PortalSites[new Uri(ConfigurationManager.AppSettings["SiteUrl"])];
PortalContext context = PortalApplication.GetContext(portal);

//initialize user profile config manager object
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile profile = profileManager.GetUserProfile(true);

wpCalendar.Title = “My Calendar”;
wpCalendar.ViewName = “Weekly”;
wpCalendar.CssClass = “”;

// use the profile object to retrieve the properties you need in your company to
// retrieve the mail box name
string workmail = profile[PropertyConstants.WorkEmail].ToString();

wpCalendar.MailboxName = workmail;
wpCalendar.OWAServerAddressRoot = ConfigurationManager.AppSettings["ExchangeServerUrl"];

wpCalendar.Height = “655″;
wpCalendar.Width = “600″;
wpCalendar.ImportErrorMessage = “No EmailID found for your account.”;
}
catch
{
litMsg.InnerHtml = “No EmailID found for your account.“;
}

return wpCalendar;
}

protected override void RenderWebPart(HtmlTextWriter output)
{
try
{
wpCalendar.RenderControl(output);
litMsg.RenderControl(output);
roundedCorner.RenderControl(output);
}
catch (Exception ex)
{
output.Write(ex.ToString());
}
}

public override void RenderControl(HtmlTextWriter writer)
{
base.RenderControl(writer);
}
}
}

Note: In above code i am pulling site url and exchange server url from the appsettings of web.config of the site.