Thursday, November 3, 2011

auto gac assemblies


in post build event in Visual Studio

"C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\gacutil.exe" -if  "$(TargetPath)"
or add gacutil.exe to path and then no need for directory

The trial period for this product has expired


kept getting "The trial period for this product has expired", and SharePoint was licenced.

Then I finished running Configuration wizard...


Office Web Apps Errors


http://www.heidibrebels.be/blog/archives/2011/office-web-apps-error-sharepoint/

Can't find the feaure
$webAppsFeatureId = $(Get-SPFeature -limit all | where {$_.displayname -eq "OfficeWebApps"}).ID
$singleSiteCollection = Get-SPSite -Identity
Enable-SPFeature $webAppsFeatureId -Url $singleSiteCollection.URL

The Web application at {) could not be found.


The Web application at {) could not be found.

Security in 2010
·         The user is a server farm administrator.
·         The user has Read and Write permissions on the content database.
·         The user is a site collection administrator.
·         The user has permissions to access the Windows SharePoint Services site or the SharePoint Server
2007 site through which the code iterates.

Impersonate

http://www.chakkaradeep.com/post/SharePoint-2010-Building-a-SharePoint-Console-Application.aspx

It was databases in the end - user login had no access.

sharepoint {0} cannot be imported because its parent {1} does not exist


I was using the SPImport and SPExport classes.  Kept getting issues.

Tried security...
then set site lock, I had set it on hoping for a performance increase, 100GB web with 5 libraries!!!!

Re-exported ...
set off site lock  Stdadm –o setsitelock –url http://yoursite –lock none

Still no luck, opened export file with winrar, edited manifest.  Looking for clues.

http://vspug.com/radi/2008/12/02/sharepoint-specific-site-content-deployment-file-cannot-be-imported-because-its-parent-web-does-not-exist/


The folder that would hold URL '/sites/1/CZ/1-40GBWE' does not exist on the server.

and then ReParent in the SPImport.


        static void spImport_Started(object sender, SPDeploymentEventArgs e)
        {
            SPImportObjectCollection rootObjects = e.RootObjects;

            foreach (SPImportObject io in rootObjects)
            {
                io.TargetParentUrl = @"http://cz.kzdev.af.didata.local/sites/1/";
            }
        }

Now its fine

Get the max nullable date from sql table in linq



        private static DateTime GetLastMigratedFilesDBLastRunDate()
        {
            DataMigratedFilesDataContext migratedFilesDataContext = new DataMigratedFilesDataContext();

            var lastExportRunDate = (from p in migratedFilesDataContext.RunDetails
                                     select (DateTime?)(p.LastExportRunDate)).Max();

            if (lastExportRunDate.HasValue)
                return Convert.ToDateTime(lastExportRunDate);
            else
                return Convert.ToDateTime("1900-01-01");
        }

Find a SPFile with CAML


     
Takes a SPFolder reference and the string  file name to search for.


        private static SPFile FindFileWithCAML(SPFolder folderToSearch, string fileName)
        {
            SPQuery query = new SPQuery();
            query.Folder = folderToSearch;

            query.Query = @"
           
               
                   
                    " + fileName + @"
               
            ";
           
            SPListItemCollection listItemsCollection = folderToSearch.DocumentLibrary.GetItems(query);

            foreach (SPListItem item in listItemsCollection)
                return item.File;

            return null;
        }

How to update the audit details of a splistitem....



How to add a user in SharePoint
user.ID + ";#" + user.Name;



czWeb.AllowUnsafeUpdates = true;

SPUser user = czWeb.EnsureUser(@"AF\jojo");
SPFile xxx = czWeb.GetFile(@"http://jojo/pricing.xlsx");

xxx.Item["Created By"] = user.ID + ";#" + user.Name;
xxx.Item.SystemUpdate(false);


How to add a user in SharePoint
xxx.Item[SPBuiltInFieldId.Modified_x0020_By] = user.ID + ";#" + user.Name;


This does not
xxx.Item["Author"] = user.ID + ";#" + user.Name;
xxx.Item["Modified By"] = user.ID + ";#" + user.Name;


At certain times, possibly because of versions,
UpdateOverwriteVersion works SystemUpdate will not.

Shrink DB Files in SQL 2008



Because you can't just shrink the db anymore without a backup.

From http://codesnippets.joyent.com/posts/show/665


declare @ssql nvarchar(4000)
set @ssql= '
if ''?'' not in (''tempdb'',''master'',''model'',''msdb'') begin
use [?]
declare @tsql nvarchar(4000) set @tsql = ''''
declare @iLogFile int
declare @sLogFileName varchar(55)
declare @RecoveryModel nvarchar(10)
declare LogFiles cursor for
select fileid from sysfiles where status & 0x40 = 0x40
open LogFiles
fetch next from LogFiles into @iLogFile
while @@fetch_status = 0
begin
set @tsql = @tsql + ''DBCC SHRINKFILE(''+cast(@iLogFile as varchar(5))+'', 10) ''
fetch next from LogFiles into @iLogFile
end
select @RecoveryModel = CONVERT(nvarchar(10),Databasepropertyex(name, ''Recovery'')) from master..sysdatabases where name = ''?''
set @tsql = ''USE [?]; '' + @tsql + '' ALTER DATABASE [?] SET RECOVERY SIMPLE '' + @tsql
set @tsql = @tsql + ''; ALTER DATABASE [?] SET RECOVERY '' + @RecoveryModel + '';''
--print @tsql --for debugging
exec(@tsql)
close LogFiles
DEALLOCATE LogFiles
end'

exec sp_msforeachdb @ssql

SharePoint Security in URL Redirection



Say there is a web called Comms, with a Document Library.  The Document Library has a folder called "Variable Accruals Report".

Users have access to this folder: "Variable Accruals Report", but not the web: Comms

So in this URL they get access denied if they try this url "http://local/IZ/Fin/Comms/default.aspx?RootFolder=%2fIZ%2fFin%2fComms%2fLibrary%2fVariable%20Accruals%20Report%2fFY%202010%20Q4%20Variable%20Accruals%20%2d%20Jun%202010%20%2d%20Aug%202010", because of the Comms/default.aspx?RootFolder bit.

As they land on this page, the page checks security and it believes no access.

But this one "http://local/IZ/Fin/Comms/Library/Forms/AllItems.aspx"will take them to the document library and show them the folders.

So the URLS show the same content, but because they get there via different address....

This item cannot be deleted because it is still referenced by other pages



I have a master page that won't go away...  You will get "This item cannot be deleted because it is still referenced by other pages" errors from SharePoint Designer and WFE.

I tried
1) putting in temp folder then deleting the temp folder - did not work.
2) Go to the Properties of the Master Page you want to remove
    Go to Content Type > Page Layout and set it to _Hidden.
3) Also tried naming and putting in another folder
4) Tried renaming to .masterX, still nothing

Its still there...

Consistent SharePoint Navigation Across Site Collection and Web Applications


Multiple site collections on multiple web applications, the problem is SharePoint will only be "aware" navigation in the the site collection.

So we need to have all the web apps, master pages and sitemaps use a custom sitemap provider.

for example:

 <siteMap>
  <siteMapNode title="xxx" url="">
    <siteMapNode title="xxx" url="/">
        <siteMapNode title="xx" url="/xx/"/>
        <siteMapNode title="x x" url="/xx/"/>
        <siteMapNode title="x" url="/x/"/>
    </siteMapNode>
    <siteMapNode title="x" url="/sites/x"/>
    <siteMapNode title="x" url="/sites/x"/>
    <siteMapNode title="x" url="/sites/x"/>
    <siteMapNode title="x" url="/sites/x"/>
  </siteMapNode>
    <siteMapNode title="x" url="app1/sites/x"/>
  </siteMapNode>
</siteMap>

Add this to _app_bin, save as mainMenu.sitemap.  This folder has special permissions, like anonymous access.

In the master page find the top nav and put this in


<SharePoint:AspMenu ID="TopNavigationMenuV4" Runat="server" EnableViewState="false" DataSourceID="topSiteMap1" AccessKey="<%$Resources:wss,navigation_accesskey%>" UseSimpleRendering="true" UseSeparateCss="false" Orientation="Horizontal" StaticDisplayLevels="1" MaximumDynamicDisplayLevels="1" SkipLinkText="" CssClass="s4-tn"/> <SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource1" Id="topNavigationDelegate"> <Template_Controls> <asp:SiteMapDataSource ShowStartingNode="false" SiteMapProvider="CustomXmlContentMapProvider" id="topSiteMap1" runat="server" /> </Template_Controls> </SharePoint:DelegateControl>





Problem: SharePoint Desginer and VS 2010 will crash if you make errors here
Must be same rendering engine?  Wierd.

then in the web.config find the siteMap section and add



Except don't use that one it would be to easy.  The above one will append to the url. So it will never work.

Instead use this assembly...
System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Voila - complete control over navigation just the way I like it.

Also this can be done in a feature...