Beyond Web Logs

Discuss technology, web development, networks and more ...

Recent posts

Tags

First time here? At BeyondWebLogs we discuss technology, web development, personal development, networks and more. You can subscribe to the RSS feed so that you keep up to date with the latest content. Now, on with the regular content...

How to retrieve User Profile info in Sharepoint using C# code API

You can use following code snippet to retrieve User Profile info in Sharepoint using C# code:

using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint.Portal.Topology;
using Microsoft.Office.Server;

ServerContext context = ServerContext.GetContext(SPContext.Current.Site);
UserProfileManager profileManager = new UserProfileManager(context);

Microsoft.Office.Server.UserProfiles.
PropertyCollection props = profileManager.Properties;

foreach (Property prop in props)
{
  Response.Write(prop.Name +
"<br/>");
}

ServerContext context2 = ServerContext.GetContext(SPContext.Current.Site);
UserProfileManager profileManager2 = new UserProfileManager(context2);

foreach (UserProfile profile in profileManager2)
{
  UserProfileValueCollection FirstNameProp = profile["AccountName"];
  Response.Write(FirstNameProp[0].ToString() +
"<br/>"); 
}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: SharePoint
Posted by Waqas on Sunday, August 17, 2008 8:20 PM
Permalink | Comments (0) | Post RSSRSS comment feed

"Cannot run windows sharepoint services on this page" Sharepoint error during multiple documents upload

If you get "Cannot run windows sharepoint services on this page" error in Sharpoint while uploading multiple documents. Following steps can be taken to resolve this issue:

1. Use default upload.aspx page from _layouts folder. Sometimes, upload.aspx becomes corrupt and overriding it with the original upload.aspx solves this problem.

2. Open Central Administration, then Application Management then Authentication Providers. Make sure you select your failed Web Application. Turn off Enable Client Integration (NO) then go back and Turn on Enable Client Integration (YES). Then IISRESET and try to upload multiple documents.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: SharePoint
Posted by Waqas on Sunday, August 17, 2008 5:36 PM
Permalink | Comments (0) | Post RSSRSS comment feed

How to get asp.net error message stack trace in sharepoint web application

In Sharepoint, if you want to get the real yellow ASP.Net page with the real error message, just update your web.config:

<SafeMode MaxControls="200" CallStack="false" ...> <!-- should be--> <SafeMode MaxControls="200" CallStack="true" ...>
 
<customErrors mode="On" /> <!-- should be--> <customErrors mode="Off" />
 
<compilation batch="false" debug="false"> <!-- should be--> <compilation batch="true" debug="true">

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: SharePoint
Posted by Waqas on Sunday, August 17, 2008 3:19 PM
Permalink | Comments (0) | Post RSSRSS comment feed

URL redirection or URL mapping in Sharepoint

URL redirection in sharepoint can be done with many different ways, but the one I have most useful is to implement it via httpmodule.
Just use following piece of code to create httpmodule and update web.config of the web application to add that module entry and everything will work fine:

namespace BWL.RedirectModule
{
    public class Redirector : IHttpModule
    {
        public void Dispose()        { }        
        public void Init(HttpApplication context)       
        {
            context.BeginRequest +=new EventHandler(context_BeginRequest);
        }        
        void context_BeginRequest(object sender, EventArgs e)
        {      
            string domain = @"(beyond)(weblog|weblogs)(.com/*$)"; //specify your URL here to be checked for redirection
            HttpApplication app = (HttpApplication)sender;
            string requestUrl = app.Request.Url.ToString(); 

            if(Regex.IsMatch(requestUrl,domain))
                app.Response.Redirect("http://beyondweblogs.com/sites/bwlportal"); // if url is found, redirect it to the new url
        }        
    }
} 

Compile it as a dll, then copy this dll to the sharepoint web application bin folder. Finally, copy following line in the web application's web.config after <httpModules> <clear />

<add name="Redirector" type="BWL.RedirectModule.Redirector" />

enJoy!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: SharePoint
Posted by waqas on Wednesday, August 06, 2008 7:40 PM
Permalink | Comments (0) | Post RSSRSS comment feed

manual backup of your windows sharepoint services [wss] site

Ever wondered how to take a full manual backup of your windows sharepoint services 3.0 [wss] site? Of course you can use stsadm command to do a full backup but you'll have to run this command every time you need to take your site's backup.

Below is a .bat script that you can use to automate this manual process. It automatically creates a filename for you and takes your wss site's backup. You can schedule this .bat file using windows schedule and your wss site's backup will take care of itself.

... and here's the script:

@echo off
echo +++++++++++++++++
echo Initializing backup...
echo Starting backup...
echo +++++++++++++++++
for /f "delims=/ tokens=1-3" %%a in ("%DATE:~4%") do (
        for /f "delims=:. tokens=1-4" %%m in ("%TIME: =0%") do (
            set FILENAME=site_backup-%%c-%%b-%%a-%%m%%n%%o%%p
        )
    )

c:
cd \Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN
@echo off
stsadm.exe -o backup -url http://server -filename D:\%FILENAME%.dat -overwrite
echo Backup complete.

Simply copy, and then save the above script as a .bat file, and that's it.

Hope it helps, as it definitely helped me. As always, thank you to all those who helped me create this script.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: ASP.NET | General | How To | SharePoint
Posted by muneeb on Monday, August 04, 2008 7:30 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Update User Profile in Sharepoint Programmatically

In Sharepoint, there is a special list ‘User Information List’ for user’s profile information storage. This list is quite handly to play around with user profile data. When a user is added to the Sharepoint site, a list item is automatically created in this list. To update the user’s information in ‘User Information List’, for instance, to update the user’s photo, I am using following code and it works fine:

SPSite
siteCollection = null;

SPWeb web = null;siteCollection =

SPContext.Current.Site;

web = siteCollection.RootWeb;

web.AllowUnsafeUpdates =
true;

Microsoft.SharePoint.SPList list = web.Lists["User Information List"];Microsoft.SharePoint.

SPUser u = web.SiteUsers[@"sharepoint\waqas"];

Microsoft.SharePoint.SPListItem it = list.Items.GetItemById(u.ID);it[

"Picture"] = "http://www.beyondweblogs.com/personal/trothman/Shared%20Pictures/Profile%20Pictures/waqas.jpg";

it.Update();

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: SharePoint
Posted by Waqas on Sunday, August 03, 2008 5:50 PM
Permalink | Comments (0) | Post RSSRSS comment feed

How to change Sharepoint Title in WSS pages

First step to change page title it is to understand where title string is stored. Easiest way to do that is to open the default.aspx page with Sharepoint Designer. We can see it contains a content block that replaces the master page's Title content placeholder.

Here is the master page extract:

<Title ID=onetidTitle><asp:ContentPlaceHolder id=PlaceHolderPageTitle runat="server"/></Title>

And here is the replacement in default.aspx:

<asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
 <SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,multipages_homelink_text%>" 
       EncodeMethod="HtmlEncode"/> - 
 <SharePoint:ProjectProperty Property="Title" runat="server"/>
</asp:Content>

We can see that the title is made up of two parts, the localized "Home" string and the current site's name taken from the site's properties. We have two options here - we can either find the resource string and change it, or remove it from the ASPX altogether (along with the connecting dash) and have a clean page title. The second option is pretty straightforward, so we'll focus on the first:

text="<%$Resources:wss,multipages_homelink_text%>" 

We can see that the actual text is retrieved from some Resource Manager. The format of the $Resources token is as follows:

$Resources:filename,localizedString

So what we need is the string "multipages_homelink_text" under the file wss.resx or wss.en-US.resx. You can find it under C:\inetpub\wwwroot\wss\VirtualDirectories\<port>\App_GlobalResources. Just change its value there and it will be instantly update the site, no IISRESET necessary.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: SharePoint
Posted by Waqas on Sunday, August 03, 2008 3:21 PM
Permalink | Comments (0) | Post RSSRSS comment feed