Take username from sharepoint link

Hi Friends,

I have one sharepoint link contains username and i want to take that username which is dynamic from sharepoint link.

Ex. Here is the sample sharepoint link.

https://abc-my.sharepoint.com/personal/userfirstname_userlastname_euroclear_com/Documents/Documents/Test2.xlsx?web=1

Suppose to get current username we can use - Environment.UserName.ToString
like what we use to get username from sharepoint link.

Thanks.

@Rup_1

You can use Regex for that as below

Now you can use split function as below

URL = “https://abc-my.sharepoint.com/personal/userfirstname_userlastname_euroclear_com/Documents/Documents/Test2.xlsx?web=1

URL.split("“c)(0) → Firstname
URL.split(”
"c)(1) → lastName

Hope this will help you

Thanks

1 Like

Hi @Rup_1,

You can use Named Groups in regex to extract the first and last name from your example link.

\/personal\/(?P<firstname>\w+)_(?P<lastname>\w+)_euroclear

Here is how it looks

More about how to extract value from Named Groups : Regex help tutorial MEGAPOST