How to get the full URL from an SPWEB
-
22-03-2021 - |
문제
I have a VB console application.
I would like to get the absolute URL of the page.
Here is my current code:
Using siteCollectSPSite As New SPSite("http://mySite")
Dim blogPostSpList As SPList
'Get only the subsite of <locale/blogs>
Using blogSiteSPWeb As SPWeb = siteCollectSPSite.OpenWeb("/blogs")
For Each subsite As SPWeb In blogSiteSPWeb.Webs
Console.WriteLine("Subsite title: " & subsite.Url)
'......
Next
Right now, what I get is: http://mySite/blogs/myblog1
What I want to get is the full URL: http://mySite/blogs/myblog1/default.aspx
How can I get the "default.aspx"?
해결책
Ok so your problem is that SPWeb doesnt actually have a 'page' as such. Default.aspx is simply one page inside the SPWeb container.
You can modify/read the default page using publishingWeb if you have the publishing feature enabled otherwise try this:
http://curia.me/post/2011/05/20/SharePoint-how-change-the-default-page-of-a-SPWeb.aspx
다른 팁
WelcomePage is the property of SPFolder type so to get the full url , you have to use :
subsite.Url + "/" + subsite.RootFolder.WelcomePage;
SPFolder.WelcomePage should have worked. If it didn't you need to set the "vti_welcomepage" in the properties of the Folder list item. This is what MS does under the hood.
if (this.m_strRedirectUrl == null)
{
string text = (string)this.Properties["vti_welcomepage"];
if (text == null)
{
text = string.Empty;
}
this.m_strRedirectUrl = text;
}
return this.m_strRedirectUrl;