What is the expression to extract the file name from a URL?
e.g. http://site/subsite/library/filename.docx
Thanks
Steve
What is the expression to extract the file name from a URL?
e.g. http://site/subsite/library/filename.docx
Thanks
Steve
hsiungst,
Without knowing your plans for the file, or the remainder of the solutin you are building, a regular expression comes to mind.
Regards,
Mike
If you have a predictable URL, i.e. the same amount of '/' characters you could do multiple Find() and Right() methods to strip out the text. Otherwise you could build a web service that parses and returns string data and hook up to an IPC event or possible pass in parameters via URL.
Another note: AFAIK SmartForms and inline expressions do not have recursion functionality, thus you'd have to build a very pattern-specific expression instead of a nice recursive parsing function.
This should match on the filename out of an arbirtrary URL. Also takes into account any arguments passed beyond that in the URL and strips em out (ex: http://www.somesite.com/folder/file.docx&someargument=nothingwecareabout
This REQUIRES http:// or https:// to be in the string to work, as something.com can look like a filename. You could modify it to be more specific if that's in your requirements by having it skip anything ending in .com/.net/.co.uk
(w+)(.w+)+(?!.*(w+)(.w+)+)
Would it be simpler and more relaible to write a service object or even a web service that u pas the url as an input
Then just use the .NET library to maybe get the read adfter the lastindex of "/" character.
Then retrun the filename as a an output.
This should match on the filename out of an arbirtrary URL. Also takes into account any arguments passed beyond that in the URL and strips em out (ex: http://www.somesite.com/folder/file.docx&someargument=nothingwecareabout
This REQUIRES http:// or https:// to be in the string to work, as something.com can look like a filename. You could modify it to be more specific if that's in your requirements by having it skip anything ending in .com/.net/.co.uk
(w+)(.w+)+(?!.*(w+)(.w+)+)
Mike, how do I use this in an expression?
Thanks
Steve
@hsiungst
You would use one of the inline functions dealing with regexp. Documentation is here: http://help.k2.com/onlinehelp/k2blackpearl/userguide/current/webframe.html#Regular_Expressions.html
Again, it depends really how/where you need to perform this logic, but, if it's in one of the places where inline functions are available you should be good to go. Note that I did not heavily test that regular expression, so you may find an edge case or two that breaks it.
I'd also suspect that .NET uses a regular expression to figure out where the last "/" character is in the URL in the web service approach, which is also workable, and may be useful in areas where an inline function cannot be used.
Regards,
Mike
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.