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...

Tuesday, July 12, 2011

Pass parameters to Silverlight web part - 2007

The web part:

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/KM.DocumentUploader.Sl.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="initParams" value="url=http://knowzonedev" />
<param name="minRuntimeVersion" value="4.0.50826.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>

In the Silverlight Visual Studio project change
RootVisual = new MainPage();
to
RootVisual = new MainPage(e.InitParams);

and then in the Page code change:

public MainPage()

to

public MainPage(IDictionary iDictionary)
{
string url = initParams["Url"].ToString();
}

voila the string variable will contain the parameters

Monday, March 14, 2011

SharePoint FBA Error

Was getting this error
The password-answer supplied is invalid

added:

enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="1"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
/>

FBA SharePoint error

"A Membership Provider has not been configured correctly. Check the web.config setttings for this web application"

changed applicationName="/" to applicationName="???"

This broke everything

FBA can be configured for multiple applications, changing the applicationName has far reaching consequences, especially when restoring

Format T-Sql

Sometimes I inherit disasters. The kids of people who make disaster are to useless to format code.

That's why I use:

http://www.ubitsoft.com/products/t-sql-beautifier/index.php

otherwise I can't tell what the h_ll is going on.

Manually editing data connection details in InfoPath 2007 forms

Imagine if someone kills the InfoPath server, and you have to get the InfoPath from the Live and then do maintenance.

First problem is that the InfoPath still wants to point to the original server.

You can fix this by renaming the .xsn to .cab, and extracting the files. open the manifest file, reset the URLS to whatever the new server is.

Then you need to turn it back into an xsn. To this, download cab maker.

In Cab Maker, create a .cab file. rename the .cab to .xsn and viola, is InfoPath again.

See http://support.microsoft.com/kb/176810 on how to make a cab


Rename edit etc

Infopath xqueru no working

This happens a lot in Infopath, XML that has different namespaces. or funnier, the namespace changes... You need code that can work out is namespace programmatically.

XPathNavigator root = MainDataSource.CreateNavigator();
string fieldValue = root.SelectSingleNode("//*[local-name()='field1']").Value;


http://www.bizsupportonline.net/blog/2009/01/specify-namespaces-use-xpath-queries-infopath/

How to connect to Excel Services with FBA

Lets say you have a site that uses forms based authentication, like an internet facing site. And then lets say that you are using Excel Services on the same farm.

So what you need is to make a cookie:

ExcelWebService.ExcelService excelService = new ExcelWebService.ExcelService();
debugWriterOutput("eService: " + excelService.Url);

excelService.CookieContainer = new CookieContainer();
excelService.CookieContainer.Add(Utilities.FBACookieAuthentication(excelService));

ExcelWebService.Status[] status;





internal static Cookie FBACookieAuthentication(ExcelWebService.ExcelService excelServiceSoapClient)
{
Authentication.Authentication auth = new Authentication.Authentication();
auth.CookieContainer = new CookieContainer();

LoginResult result = auth.Login("LoginName", "Password");

CookieCollection cookies = auth.CookieContainer.GetCookies(new Uri(auth.Url));

Cookie authCookie = cookies[result.CookieName];

return authCookie;
}

SharePoint stsadm scheduled backup

This summary is not available. Please click here to view the post.

Can't access SharePoint site after restore

This summary is not available. Please click here to view the post.

Find Tables in SQL by column names

if you are like me and often get called in to stabilize a disaster, you will need to get an understanding of the database really fast, and seen as its a disaster there will be no-one to explain the schema

This useful script will help you to find the links



find tables in sql with cols =


DECLARE search_Cursor CURSOR
FOR select o.name from sysobjects o where o.name like 'XXX%' and type = 'u' order by o.name

OPEN search_Cursor

declare @TableName varchar(100)

FETCH NEXT FROM search_Cursor
INTO @TableName


WHILE @@FETCH_STATUS = 0
begin

declare @ExecString varchar(250)

select @ExecString = ' select * from ' + @TableName + ' where Status = ''' + 'd' + ''''

print @ExecString
exec (@ExecString)


FETCH NEXT FROM search_Cursor
INTO @TableName

end

CLOSE search_Cursor
DEALLOCATE search_Cursor
GO

Task failed because "sgen.exe" was not found

If you get this error just copy the file, don't even need the sdk

Error 1 Task failed because "sgen.exe" was not found, or the .NET Framework SDK v2.0 is not installed. The task is looking for "sgen.exe" in the "bin" subdirectory beneath the location specified in the SDKInstallRootv2.0 value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework. You may be able to solve the problem by doing one of the following: 1.) Install the .NET Framework SDK v2.0. 2.) Manually set the above registry key to the correct location. 3.) Pass the correct location into the "ToolPath" parameter of the task. Unlock

Task failed because "sgen.exe" was not found


If you get this error just copy the file, don't even need the sdk

Error 1 Task failed because "sgen.exe" was not found, or the .NET Framework SDK v2.0 is not installed. The task is looking for "sgen.exe" in the "bin" subdirectory beneath the location specified in the SDKInstallRootv2.0 value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework. You may be able to solve the problem by doing one of the following: 1.) Install the .NET Framework SDK v2.0. 2.) Manually set the above registry key to the correct location. 3.) Pass the correct location into the "ToolPath" parameter of the task. Unlock

Users can't open office docs

This one plagues SharePoint installations.

Users can't open document in libraries from a link, they get multiple prompts, nothing happens

See problems here:
http://support.microsoft.com/kb/932118
http://support.microsoft.com/kb/871155
http://blogs.msdn.com/b/sharepoint/archive/2007/10/19/known-issue-office-2007-on-windows-vista-prompts-for-user-credentials-when-opening-documents-in-a-sharepoint-2007-site.aspx

See solutions here
http://www.uv.mx/personal/gvera/2010/09/28/sharepoint-login-prompt-when-accessing-files-in-a-document-library/
http://stackoverflow.com/questions/375390/office-documents-prompt-for-login-in-anonymous-sharepoint-site

Infopath Schema not Updating

Had an InfoPath form that calls a web service, that calls a SQL Procedure.

Logic in the stored proc was causing it return datasets that looked the same, the result sets were created dynamically. Problem was they had different datatypes. So when run the form you get strange behavior.

You could do an ODBC trace, which will show you how the procs callers (the drivers) do to the datatypes.

Or, you could have the proc fill a temp table, this way the result set it always the same

The form template is not browser-compatible

I have some InfoPath forms that I need to upload, I keep getting this error, "The form template is not browser-compatible. It might be possible to correct the problem by opening the form template in Microsoft Office InfoPath, and then republishing it."

Except, I can't figure out why. It will disappear after some beating.

http://www.thorprojects.com/blog/archive/2008/03/11/infopath-forms-services-%E2%80%93-the-form-template-is-not-browser-compatible.aspx
http://sharepointtopics.blogspot.com/2008/07/domain-certificate-authority-signing.html

These are Administrator Approved Browser-enabled Forms, they must be uploaded in Central Administration.

Some things I try when getting this to upload:
There was no Submit sheesh, make submit option to "using rules"
Publish to a document library on the server.... oy vey its Admintrator Approved...
Changed submit options on and off, set verions higher, published to library, Published to library, uploaed. worked
Submit may not contain &...I took out the & shortcut key
Close all pages that show the form... not sure...
Switch off caching of data connections
Got to certificates, install to recommended, install to trusted certificates authority, then publish to moss, then file and upload...have since found that the code signing makes no difference
Took off submit, published to sharepoint library, then to network
Added digital certificate, published to sharePoint, then to network/file system
iisreset
reboot