Sunday, October 14, 2012

feature activation code using powershell does not pick appsettings values

This is a  very common scenario where , our deployment guides tend to be useless with automation just because features are activated well using UI in settings of site/site collection  , but fail using powershell.

Here is the solution to this :


using (SPWeb web = properties.Feature.Parent as SPWeb)
{
SPWebApplication webApp = web.Site.WebApplication;
Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webApp.Name);
// App settings are retrieved this way
config.AppSettings.Settings["someAppSettingKey"].Value;


// Connection string settings are retrieved this way
config.ConnectionStrings.ConnectionStrings["someDBConnectionString"].ConnectionString
web.Site.Dispose();
}


 

Reference :

Read web.config on FeatureActivated event while activating Feature using PowerShell

 

Wednesday, October 10, 2012

Get Dependent files from HTML response

Hi

I am getting response of a page like :

System.Net.HttpWebRequest  request  ...

request.Credentials...

request.Method = ...

request.UserAgent =..

(System.Net.HttpWebResponse)request.GetResponse();

receiveStream = response.GetResponseStream();

readStream = new StreamReader(receiveStream, Encoding.UTF8);

string pageContent = readStream.ReadToEnd();

Now out of this string pageContent    , I want to extract all sub request and make them a hit.   Is there something better than html agility pack for this ?

Reply 1 By http://social.msdn.microsoft.com/profile/joel%20engineer/?ws=usercard-mini

I usually read it into an htmlDocument Class and the use either GetElementByID or GetElementsByTagname()

 

 

 

string pageContent;

webBrowser1.Document.Write(pageContent);

 




jdweng

 

Reply 2 


You should try http://htmlagilitypack.codeplex.com/

I am searching something better dear.

Tuesday, September 25, 2012

Dummy Workflow References

Hi

 


    •  For my Document Library WorkflowAssociations.Count  is zero.

    • For this document Library EnableModeration  is false.

    •  Still I can see column in the document Library named "Approval Status".  (internal name   "_ModerationStatus")



When I try to set  EnableModeration  true for this document library , I get exception.

Seems to be some time in the past workflow was enabled on this list / enablemoderation was true . But setting these to negative did not remove Approval Status column.

How I can fix this document library without deletion , so that  future workflows enabled or enablemoderation=true should not give exception ?

Monday, August 6, 2012

User Policy to restrict Form Authentication Users from visitingapplication pages like viewlsts.aspx

• On web application management ( e.g. http://ServerName:CentralAdminPort/_admin/WebApplicationList.aspx) page under central admin , go to Permission Policy :


• Mark the check box which says deny users to view application pages and save.

• Output is :

• Now go to user policies tab for main web application and click on add user :


• Select the zone on which public main application is deployed :

• Under people picker type "ASP.NET Membership provider name" , Permissions : Deny System Pages and click finish :

• Output is like :

Now access few application pages and lists directly to verify with a form authentication user .


Alternative approach and suggestions are welcome under comments section.

Friday, August 3, 2012

0x80070057 sharepoint variations

On page http://ServerName/_Layouts/VariationLogs.aspx , when I ran Timer Job "Variations Create Hierarchies Job Definition" , I was getting the error ( Under Failures column) :

The Variations Create Hierarchies job failed with the following error message: <nativehr>0x80070057</nativehr><nativestack></nativestack>.

I was getting below mentioned errors in ULS logs :

Process : OWSTimer.exe
Area : Web Content Management
Category : Site Management
Level : Unexpected




CreateVariationHierarchiesJob catches Exception. System.ArgumentException: <nativehr>0x80070057</nativehr><nativestack></nativestack> at
Microsoft.SharePoint.Library.SPRequestInternalClass.GetMetadataForUrl(String bstrUrl, Int32 METADATAFLAGS, Guid& pgListId, Int32& plItemId, Int32& plType, Object& pvarFileOrFolder) at
Microsoft.SharePoint.Library.SPRequest.GetMetadataForUrl(String bstrUrl, Int32 METADATAFLAGS, Guid& pgListId, Int32& plItemId, Int32& plType, Object& pvarFileOrFolder) at
Microsoft.SharePoint.SPWeb.GetFileOrFolderObject(String strUrl) at Microsoft.SharePoint.Publishing.CommonUtilities.GetFileFromUrl(String url, SPWeb web) at
Microsoft.SharePoint.Publishing.PublishingPage.get_Layout() at Microsoft.SharePoint.Publishing.PublishingPage.set_Layout(PageLayout value) at
Microsoft.SharePoint.Publishing.Internal.DeploymentWrapper.CreateVariantPage(PublishingPage sourcePage, PublishingWeb targetArea, String destPageWebRelativeUrl, String pageLayoutName, String title, String
description, Boolean copyResources, Boolean enforceMajorVersion, SPWeb& webToClose, PageLayout[] targetAreaAvailablePageLayouts) at Microsoft.SharePoint.Publishing.PublishingPage.CreateVariationInner
(VariationLabel varlabel, String pageLayoutName, String destPageName, String title, String description, Boolean copyResources, Boolean overrideStopUpdate, Boolean isCreateHierarchies, Boolean
enforceMajorVersion, Boolean skipIdentityTargetConflictChecks, Boolean stopAutoSpawnAfterDelete, Boolean sendNotificationEmail, LongRunningOperationJob lroLogger, PublishingWeb targetArea, PageLayout[]
targetAreaAvailablePageLayouts, Hashtable variationPageLayoutTable) at Microsoft.SharePoint.Publishing.PublishingPage.CreateVariationAuto(CachedVariationSettings variationSettings, VariationLabel
varlabel, Boolean isCreateHierarchies, Boolean enforceMajorVersion, Boolean skipIdentityTargetConflictChecks, LongRunningOperationJob lroLogger, PublishingWeb targetArea, PageLayout[]
targetAreaAvailablePageLayouts, Hashtable variationPageLayoutTable) at Microsoft.SharePoint.Publishing.PublishingWeb.<>c__DisplayClass3e.<CreateVariationsDeepForCurrentPages>b__38(SPListItem item) at
Microsoft.Office.Server.Utilities.ContentIterator.ProcessItem(SPListItem item, Boolean fIncludeFolderItems, MonitoredScopeWrapper monitoredScopeWrapper, ItemProcessor itemProcessor, ItemProcessorErrorCallout
errorCallout) at Microsoft.Office.Server.Utilities.ContentIterator.ProcessItems(SPListItemCollection items, Boolean fIncludeFolderItems, Boolean fIterateInReverseOrder, MonitoredScopeWrapper
monitoredScopeWrapper, ItemProcessor itemProcessor, ItemProcessorErrorCallout errorCallout) at Microsoft.Office.Server.Utilities.ContentIterator.ProcessItems(SPListItemCollection items, Boolean
fIncludeFolderItems, Boolean fIterateInReverseOrder, ItemProcessor itemProcessor, ItemProcessorErrorCallout errorCallout) at
Microsoft.SharePoint.Publishing.PublishingWeb.<>c__DisplayClass3e.<CreateVariationsDeepForCurrentPages>b__37(SPListItemCollection items) at
Microsoft.Office.Server.Utilities.ContentIterator.ProcessListItems(SPList list, SPQuery query, ItemsProcessor itemsProcessor, ItemsProcessorErrorCallout errorCallout) at
Microsoft.Office.Server.Utilities.ContentIterator.ProcessListItems(SPList list, String strQuery, UInt32 rowLimit, Boolean fRecursive, SPFolder folder, ItemsProcessor itemsProcessor,
ItemsProcessorErrorCallout errorCallout) at Microsoft.Office.Server.Utilities.ContentIterator.ProcessListItems(SPList list, String strQuery, UInt32 rowLimit, Boolean fRecursive, ItemsProcessor
itemsProcessor, ItemsProcessorErrorCallout errorCallout) at Microsoft.SharePoint.Publishing.PublishingWeb.CreateVariationsDeepForCurrentPages(CachedVariationSettings variationSettings, VariationLabel
varlabel, Boolean isCreateHierarchies, LongRunningOperationJob lroLogger, List`1 errors, Hashtable variationPageLayoutTable) at
Microsoft.SharePoint.Publishing.PublishingWeb.<>c__DisplayClass34.<CreateVariationsDeepForChildPages>b__30(SPWeb web) at Microsoft.Office.Server.Utilities.CultureUtility.RunWithCultureScope
(CodeToRunWithCultureScope code) at Microsoft.Office.Server.Utilities.ContentIterator.ProcessSite(SPSite site, Boolean fSetThreadCulture, WebProcessor webProcessor, WebProcessorErrorCallout errorCallout)
at Microsoft.Office.Server.Utilities.ContentIterator.ProcessSite(SPSite site, WebProcessor webProcessor, WebProcessorErrorCallout errorCallout) at
Microsoft.SharePoint.Publishing.PublishingWeb.<>c__DisplayClass34.<CreateVariationsDeepForChildPages>b__2f(SPSite rootSite) at Microsoft.Office.Server.Utilities.TimerJobUtility.ProcessSite(SPSite site,
SiteProcessor siteProcessor) at Microsoft.SharePoint.Publishing.PublishingWeb.CreateVariationsDeepForChildPages(CachedVariationSettings variationSettings, VariationLabel varlabel, Boolean
isCreateHierarchies, LongRunningOperationJob lroLogger, List`1 errors, Hashtable variationPageLayoutTable) at Microsoft.SharePoint.Publishing.PublishingWeb.CreateVariationsDeepForChildren
(CachedVariationSettings variationSettings, PublishingWeb sourceParentPubWeb, VariationLabel varlabel, Boolean isCreateHierarchies, LongRunningOperationJob lroLogger, List`1 errors) at
Microsoft.SharePoint.Publishing.PublishingWeb.CreateVariationsDeep(CachedVariationSettings variationSettings, ReadOnlyCollection`1 varLabels, Boolean isCreateHierarchies, Boolean recurse,
LongRunningOperationJob lroLogger, List`1 errors) at Microsoft.SharePoint.Publishing.Internal.CreateVariationHierarchiesJobDefinition.PerformVariationsSpawn(SPWorkItem workItem, SPWeb currentWeb,
CachedVariationSettings variationSettings)





Process : OWSTimer.exe
Area : Web Content Management
Category : Site Management
Level : Unexpected



PublishingWeb::CreateVariationsDeepForCurrentPages caught Exception at item 'Pages/Folder1/Folder2/PageName.aspx' with : <nativehr>0x80070057</nativehr><nativestack></nativestack>







Process : OWSTimer.exe
Area : Web Content Management
Category : Publishing
Level : Monitorable




GetFileFromUrl: ArgumentException when attempting get file Url http://OldServerName/_catalogs/masterpage/PageLayoutFileName.aspx <nativehr>0x80070057</nativehr><nativestack></nativestack> at
Microsoft.SharePoint.Library.SPRequestInternalClass.GetMetadataForUrl(String bstrUrl, Int32 METADATAFLAGS, Guid& pgListId, Int32& plItemId, Int32& plType, Object& pvarFileOrFolder) at
Microsoft.SharePoint.Library.SPRequest.GetMetadataForUrl(String bstrUrl, Int32 METADATAFLAGS, Guid& pgListId, Int32& plItemId, Int32& plType, Object& pvarFileOrFolder) at
Microsoft.SharePoint.SPWeb.GetFileOrFolderObject(String strUrl) at Microsoft.SharePoint.Publishing.CommonUtilities.GetFileFromUrl(String url, SPWeb web)





Process : OWSTimer.exe
Area : SharePoint Foundation
Category : General
Level : High



<nativehr>0x80070057</nativehr><nativestack></nativestack>





Process : OWSTimer.exe
Area : Web Content Management
Category : Site Management
Level : Unexpected




PublishingWeb::CreateVariationsDeepForChildPages() caught Exception at web 'http://NewServerName/es-LA/Subsite1' with : <nativehr>0x80070057</nativehr><nativestack></nativestack>





Process : OWSTimer.exe
Area : Web Content Management
Category : Site Management
Level : Unexpected




DeploymentWrapper::CreateVariantPage() on sourcePage = 'Pages/Folder1/Folder2/PageName.aspx', targetWeb = 'http://NewServerName/es-LA/Subsite1' catches an unexpected exception: System.ArgumentException:
<nativehr>0x80070057</nativehr><nativestack></nativestack> at Microsoft.SharePoint.Library.SPRequestInternalClass.GetMetadataForUrl(String bstrUrl, Int32 METADATAFLAGS, Guid& pgListId, Int32& plItemId,
Int32& plType, Object& pvarFileOrFolder) at Microsoft.SharePoint.Library.SPRequest.GetMetadataForUrl(String bstrUrl, Int32 METADATAFLAGS, Guid& pgListId, Int32& plItemId, Int32& plType, Object&
pvarFileOrFolder) at Microsoft.SharePoint.SPWeb.GetFileOrFolderObject(String strUrl) at Microsoft.SharePoint.Publishing.CommonUtilities.GetFileFromUrl(String url, SPWeb web) at
Microsoft.SharePoint.Publishing.PublishingPage.get_Layout() at Microsoft.SharePoint.Publishing.PublishingPage.set_Layout(PageLayout value) at
Microsoft.SharePoint.Publishing.Internal.DeploymentWrapper.CreateVariantPage(PublishingPage sourcePage, PublishingWeb targetArea, String destPageWebRelativeUrl, String pageLayoutName, String title, String
description, Boolean copyResources, Boolean enforceMajorVersion, SPWeb& webToClose, PageLayout[] targetAreaAvailablePageLayouts).





Possible Reason :

1. You have recently moved your content db from an old server , the display names for page layouts seems to be updated ( even on mouse hover) but internally older server name is being referred.
2. Even after updating page layout via object model , publishing cache is not flushed.
Possible Resolution:

1.

For all the Publishing pages under source variation , update property "PublishingPageLayout" to http://NewServerName/_catalogs/masterpage/PageLayoutFileName.aspx [ old value
http://OldServerName/_catalogs/masterpage/PageLayoutFileName.aspx ]
page.ListItem.Properties["PublishingPageLayout"] = newPageLayout;

2. Flush object cache at http://ServerName/_Layouts/objectcachesettings.aspx
3. IISRESET
4. Restart owstimer.exe
5. Under http://ServerName/_Layouts/VariationLabels.aspx again schedule create Hierarchies.
6. Have a cup of tea.
7. Start the Timerjob 'Variations Create Hierarchies Job Definition’ manually or wait for the schedule.
8. Keep an eye on http://ServerName/_Layouts/VariationLogs.aspx

Thursday, August 2, 2012

Access "Pages" Library for Chinese Locale

Hi

My site collection has 5 language variations.

 

Except Chinese version I am able to access Pages Library Like :

web.Lists["Pages"] or web.Lists.TryGetList("Pages")  .

 

But for Chinese sub site :

  1. If I Iterate   web.Lists   collection  using foreach loop , there is a list present whose SPList.Title is "Pages" . For this list Under SPList.SchemaXml , Title is Title="頁面"

  2. web.Lists["Pages"] gives error: List 'Pages' does not exist at site with URL 'XXXXXXXXXXXXXXXXXXXXXXXXX' AND  web.Lists.TryGetList("Pages")   gives null .

  3. But web.Lists["頁面"]  returns the right SPList object


Is it like , SharePoint API's to retrieve a list by name refer to  SchemaXml   rather than SPList.Title , while retrieving a list internally ?

 

 

 

Reply 1 by http://social.technet.microsoft.com/profile/ivan%20vagunin/?ws=usercard-mini

Hi!

I would propose to use SPWeb.GetList function - it returns list by url (eg web.GetList("/myweb/Pages") and url usually the same for all locales.

http://msdn.microsoft.com/ru-ru/library/microsoft.sharepoint.spweb.getlist(v=office.12).aspx

reply 2 By http://social.technet.microsoft.com/profile/aseem%20sood/?ws=usercard-mini

All the options that I can come up with are:

 

  1. Web.GetList(<Url from SharePoint Resource File>) Preferred over the others for Intranet

  2. PublishingWeb.PagesList (Coz it was specifically mentioned for Pages Library)

  3. SPWeb.GetListsOfType ( with 850 for Pages Library. If it does not work then 101-Document Library and Loop through)

  4. Guid LibraryPagesId = PublishingWeb.GetPagesListId(web); SPList psgeslib = web.Lists[LibraryPagesId];


Also, just wanted to add Web.GetList(URL) is normally a better performing approach than Web.Lists[ID/TITLE].

Thanks,

Aseem Sood

Monday, July 9, 2012

SharePoint 2010 | Content Deployment using Path and Jobs from Central Admin | Errors

Hi

We have a staging source and target production.  For 1st migration on blank site collection :

1. Even if we migrate content to a blank site collections we get many warnings like :

a.

[WebFeature] [Publishing]   Warning: Provisioning did not succeed. Details: Failed to create the 'Images' library. OriginalException: The feature failed to activate because a list at 'PublishingImages' already exists in this site.  Delete or rename the list and try activating the feature again.

b.

Warning: Provisioning did not succeed. Details: Failed to create the 'Images' library. OriginalException: The feature failed to activate because a list at 'PublishingImages' already exists in this site.  Delete or rename the list and try activating the feature again.

c.

Warning: User or group 19 cannot be resolved.

 

 Can we use a backup of staging as target instead of blank . What else than initial migration failure should I aspect as drawback in this ?

 

2.

Content deployment deploys the most recent major and minor versions of a content item. For example, if version 2.7 of a Web page is being deployed, the most recent major version (2.0) of the page, and the most recent minor version (2.7), will be deployed to the destination site.

Is it possible to limit the migration to last major version only ?

  1. We have started with blank site collection using powershell. Still getting the error in point one.

  2. I refer to http://centralAdmin/_admin/Deployment.aspx in this problem statements above.


Reply 1 By http://social.technet.microsoft.com/profile/jason%20warren/?ws=usercard-mini

Microsoft's Stefan Goßner has a great post about content deployment that I recommend you review.

 

In the section about the requirements for a successfuly content deployment, he recommends using an empty site collection for the destination and not a site collection with the Blank Site template (STS#1):
3) Use an empty site collection as the destination of your content deployment job

As already discussed in Part 5 content deployment will fail if the destination database contains conflicting content. To avoid this it is required that the initial deployment is done into an empty site collection.

Be aware that the only way to create an empty site collection is to use the following STSADM command:

STSADM.EXE -o createsite -url <url-to-site-collection> -ownerlogin domain\user -owneremail <email-address>

Using the "Blank Site" template will NOT create an empty site collection! It will actually create a site collection with content. You can see the difference if you create a site collection using both methods and then inspect the content of the created sites using SharePoint designer.

I personally recommed to always use the STSADM command with the syntax above to ensure that you really have an empty site collection as destination.

Impact: If the site collection has been created using a different method or already contains data the content deployment job will fail.

How to resolve: Deploy into an empty site collection

For your second question, content deployment will deploy the latest published version. If you don't want a minor version to be deployed (it's a draft, perhaps), simply do not publish it.




 

JASON WARREN

Infrastructure Specialist



 


 Reply 2 By http://social.technet.microsoft.com/profile/neal%20mcfee%20%5Bmct%5D/?ws=usercard-mini

To create a site collection that does not have a template (an empty site template) you omit the -template parameter in the New-SPSite cmdlet.

If you create a blank site using the STS#0, this will not work for the task you are trying to complete.

 

 

Try deleting the target site collection and recreating it using New-SPSite but do not specify the template.

Then re-run your publishing job.




If this helps you then please mark the post as helpful.
If this answers your question then mark it as the answer.
If another contributor in the thread answers your question then please do the right thing.
And as always most answers for SharePoint are based on "It depends"