URLni qatorga ajratish

URLni bir qatorga ajrating va uni qanday qilib to'g'ri bajarilishini aniqlab olishda qiyinchiliklarga duch kelganman. Bu biroz murakkab.

Shuning uchun mening URL manzilim shunday bo'ladi:

http://sharepoint/webname/libraryname/subfolder1/pastki papka2/pastki papka3/documentname

Va natijalar shunga o'xshash bo'lishi kerak

array0 - http://sharepoint
array1 - webname
array2 - libraryname
array3 - subfolder1/subfolder2/subfolder3 
array4 - documentname

Har qanday yo'l-yo'riqni qadrlayman.

1

4 javoblar

Bu men uchun ishlaydi:

var uri = new Uri(@"http://sharepoint/webname/libraryname/subfolder1/"
    + "subfolder2/subfolder3/documentname");

var segments =
    uri.Segments
        .Select(s => s.EndsWith("/") ? s.Substring(0, s.Length - 1) : s)
        .ToArray();

var array = new []
{
    String.Format("{0}://{1}", uri.Scheme, uri.Host),
    segments[1],
    segments[2],
    String.Join("/", segments.Skip(3).Take(segments.Length - 4)),
    segments[segments.Length - 1],
};

Men ushbu natijani olaman:

Parsed Uri Array

6
qo'shib qo'ydi
Bu juda ajoyib, misol uchun rahmat.
qo'shib qo'ydi muallif PixelMuse, manba

Agar Uri sinfidan foydalansangiz, u Segmentlar xususiyati sizga yo'llarning tarkibiy qismlarini string majmuasi sifatida beradi

2
qo'shib qo'ydi

Uri-ni ajratish uchun System.Uri dan foydalaning. Keyin String.Split dan foydalanishingiz mumkin.

1
qo'shib qo'ydi

Uri sinfidan foydalaning.

1
qo'shib qo'ydi