Current User's login Name in a list item
We have a list in MOSS 2007 which contains a number of web links (URLs of external and internal sites). Out of these, some URLs require the logged in user's user name to be placed within specific placeholders within the URL (e.g. http://www.somesite.com/access/[username]/index.aspx). Is there an easy way to accomplish this in MOSS? We have thought of several workarounds
1. Quick and dirty way is to have a link (in the List) that points to an ASPX page, which in turn does a URL re-direction to the correct URL with the login name substituted.
2. Write a custom web part (like a ASP.NET LinkButton control that reads the URL from an XML config file and adds the user name in the appropriate place (this cannot be placed in the list though)
How can I get this accomplished?
Answers
- If I understand your question correctly , you are saying that you want links to external and internal sites (these sites not MOSS, at lease from your provided URL pattern it seems like that) with certain pattern like http://www.somesite.com/access/[username]/index. For dymanic URL creation as per login user perhaps your can use the webpart , where links are still store in some lists (perhaps links list or custom list) , so during render method of webpart you gather the links from "custom list " and replace "[username]" with current login user on the site. You can use " SPWeb.CurrentUser.Name " to get the current login user.
So in your case you essentially mantain the links in "custom sharepoint lists , or links list" like following
http://www.somesite.com/access/[username]/index.aspx
http://www.somesite.com/access/[username]/details.aspx
If you really dont want to use SharePoint list approch to store the URL's , you can also use webpart properties , to store the links in it. see following links for more information on web part custom properties.
http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx
http://www.15seconds.com/issue/040218.htm
http://razi.spaces.live.com/- Marked As Answer byCharlie WuModeratorWednesday, November 11, 2009 2:11 AM
- I am not too sure that "Me" in calculated column will work in your scenario ,if you want to know the details I will recommend you to read http://www.apptheory.com/sharepoint/sharepoint_blogs/articletype/articleview/articleid/158/calculated-columns-vs-today-amp-me.aspxPerhaps at this junction , you can get the desired results by writing a simple webpart as mention in my previous post , you can still use your Links List as a source for the links , but during the rendering of webpart replace "[username]" with actual logged in user. This will guarantee correct URL.
http://razi.spaces.live.com/- Marked As Answer byCharlie WuModeratorWednesday, November 11, 2009 2:11 AM
All Replies
- If I understand your question correctly , you are saying that you want links to external and internal sites (these sites not MOSS, at lease from your provided URL pattern it seems like that) with certain pattern like http://www.somesite.com/access/[username]/index. For dymanic URL creation as per login user perhaps your can use the webpart , where links are still store in some lists (perhaps links list or custom list) , so during render method of webpart you gather the links from "custom list " and replace "[username]" with current login user on the site. You can use " SPWeb.CurrentUser.Name " to get the current login user.
So in your case you essentially mantain the links in "custom sharepoint lists , or links list" like following
http://www.somesite.com/access/[username]/index.aspx
http://www.somesite.com/access/[username]/details.aspx
If you really dont want to use SharePoint list approch to store the URL's , you can also use webpart properties , to store the links in it. see following links for more information on web part custom properties.
http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx
http://www.15seconds.com/issue/040218.htm
http://razi.spaces.live.com/- Marked As Answer byCharlie WuModeratorWednesday, November 11, 2009 2:11 AM
- Thank you very much for your response. I guess I was not very clear with my question.
What I have is a simple list in SharePoint that contains a list of links. Most of these links are simple links, but a few of them require the current user's login name to be present in the URL (e.g. http://www.somesite.com/access/[username]/index). I tried using a calculated column in the list and the Me function - but MOSS does not allow me to use the "Me" function in a calculated column.
How can I have an item in a SharePoint list to contain the current user's login name? - I am not too sure that "Me" in calculated column will work in your scenario ,if you want to know the details I will recommend you to read http://www.apptheory.com/sharepoint/sharepoint_blogs/articletype/articleview/articleid/158/calculated-columns-vs-today-amp-me.aspxPerhaps at this junction , you can get the desired results by writing a simple webpart as mention in my previous post , you can still use your Links List as a source for the links , but during the rendering of webpart replace "[username]" with actual logged in user. This will guarantee correct URL.
http://razi.spaces.live.com/- Marked As Answer byCharlie WuModeratorWednesday, November 11, 2009 2:11 AM


