Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have list with 500+ records. There is a hyperlink column called "TargetURL". As all of us know SP saves hyperlink in ["http://portal.site.com/sitecoll/doclib/Forms/someview.aspx", description ] format.

I have a workflow and I need to extract the doclib portion from the URL segment so I can get the document library name. Possible?

Substring? but how ? any tips will be appreciated.

share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

This worked for me but I had to put first result in a variable and then add another build string action

http://[^/]+/[^/]+/

http://portal.cab.com/SalessiteCollection/October2012Library/Forms/customview.aspx Result: October2012Library/Forms/customview.aspx (you can store this in a variable)

(/Forms.*)

October2012Library/Forms/customview.aspx Result: October2012Library

share|improve this answer
    
Bill: This worked. Just 2 steps. If someone can combine both regex into one that would be even great. LOL. Thanks –  M. Todd Oct 8 '12 at 18:05
add comment

Yes,

Have you tried this?

SPWeb web = SPContext.Current.Web;
string listname = String.Empty;
try
{
    SPList list = web.GetList(HttpContext.Current.Request.RawUrl);
    if (null != list)
    {
        listname = list.Title;
    }
}
catch (System.IO.FileNotFoundException ex) 
{
    //... Handle the exception 
}
share|improve this answer
    
Daniel: Not sure how this helps me. I have 1 list with 500+ records. And there is a hyperlink column that's populated with links to various document libraries. I am simply trying to get the document library name from the hyperlink column. –  M. Todd Oct 8 '12 at 16:46
    
With this code, changing the "HttpContext.Current.Request.RawUrl" by your url, you will get the Document Library name... But I agree that is not performatic. In your case, there will be a pattern like you posted site/sitecoll/doclib... it will always be this way? –  Daniel Pinto Oct 8 '12 at 16:48
    
sharepoint.stackexchange.com/questions/40712/… almost looks like it. I dont see any substring after or before function in WF. they are only available xslt. –  M. Todd Oct 8 '12 at 16:48
    
var url = "site/sitecoll/doclib/Forms/AllItems.aspx";; var docLib = url.Replace("http://", string.Empty).Split('/')[2]; –  Daniel Pinto Oct 8 '12 at 16:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.