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 two site collections as Portal1 and Portal2. In Portal2, I have enterprise search centre and will add custom Search scope for Portal1 site collection using C#. I deployed project in Portal2 and activated feature. With properties.Feature.parent as SPSite, I got Site of Portal2. How can I get Portal1 (SpSite site)?

scope.Rules.CreateUrlRule(ScopeRuleFilterBehavior.Include, UrlScopeRuleType.HostName, site.RootWeb.Url);

Site.RootWeb.Url should get URL of Portal1.

Thanks

share|improve this question
add comment

migrated from stackoverflow.com Apr 26 '12 at 10:00

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 0 down vote accepted

If you know the url of Portal1, you can directly use it instead of site.RootWeb.Url. If you need SPSite object of Portal1 you can use :

using (SPSite oSiteCollection = new SPSite([Portal1Url]))
{
...
}

If you dont know the url of Portal1,You should know have at least one property to find the site collection in the web application.Below is the example if you know Title of rootweb:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
if (site != null)
{
SPWebApplication webApp = site.WebApplication;
string targetUrl = string.Empty;
foreach (SPSite siteToSearch in webApp.Sites.Where
(siteToSearch => siteToSearch.RootWeb.Title == "Portal1 Title"))
{
   targetUrl = siteToSearch.Url;
}

}
}
share|improve this answer
    
Thanks Amit, your example works fine for my solution. But I decided to solve my issue with property bag. I set the property with powershell. Then, I get the site from SPFarm.Local.Properties. –  mkacar Apr 26 '12 at 13:45
add comment

If you are trying to get the URL for Portal1 from a feature activated in Portal2 you will need to either get it from the SPWebApplication and use logic to determine which SPSite object to use, use a hard-coded URL to create a Portal1 SPSite object, or use a feature property to define the URL to use to create a Portal1 SPSite object.

Somewhere along the line you will have to define a hard-coded or property-based value that will enable you to create an SPSite object, unless you know a way to achieve the same using logic.

Hope this helps.

share|improve this answer
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.