Sunday, October 14, 2012

MVC 4 Bundling


Also http://forums.asp.net/t/1776599.aspx/1?MVC+4+0+Bundling+Minification+not+working+


Add to the  View\Web.config :

 
 
   

 

and the following inside View\....cshtml

@if (IsSectionDefined("scripts"))
{
       @RenderSection("scripts", required: false)
}.


Still got errors, so  work around was needed as I had a demo and 2012 release was only in a week....

add    

to



   
    @ViewBag.Title - Movie App
   
   
   
   
   
   
   
   



Master Detail View in MVC4/Razor is easy



///Master


@model MyDataFirst.Master
@{
    ViewBag.Title = "Master";
}


       
           
               
@Model.MasterName

           



//Detail


                    @{ if (Model.Detail != null)
                       {
                           foreach (var item in Model.Detail)
                           {
                       
                           
                                @item.Detail
                           
                       
                           }
                       }
                    }
               


Entity Framework connection string


connectionString="metadata=res:///Model.Project.csdl|res:///Model.Project.ssdl|res://*/Model.Project.msl;

change to

connectionString="metadata=res://*/;

Installing the performance counter strings for service ASP.NET_64 (ASP.NET_64) failed


This is a doozy.  You will not be able to install SharePoint 2010, or change IIS features.  I tried reinstalling frameworks, fiddling in IIS etc.

In the event log you will get
Installing the performance counter strings for service ASP.NET_64 (ASP.NET_64) failed. The first DWORD in the Data section contains the error code.
and
Unable to install counter strings because the SYSTEM\CurrentControlSet\Services\ASP.NET_64\Performance key could not be opened or accessed. The first DWORD in the Data section contains the Win32 error code.

What I did was create a SYSTEM\CurrentControlSet\Services\ASP.NET_64\Performance key (only ASP.NET_64_2.0.50727 exists).
I completely uninstalled IIS and all components, restarted and then redid the IIS I needed to run SharePoint 2010 on my Windows7 machine,

The name ‘InitializeControl’ does not exist in the current context


You may just receive an error like so.
"The name ‘InitializeControl’ does not exist in the current context” – Visual Web Part (Sandboxed) bug and how to fix it

in Visual Studio in a SharePoint Visual Web Part 2012 in a Sandboxed solution.

My error was a "'" as in "'<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>"
instead of "<%@ "

Sorted.

Saturday, October 13, 2012

SharePoint Online viewstate maximum


Big problem, if the viewstate in a SharePoint Online webpart exceed 128KB it breaks with

Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred.

Try setting controls to no use viewstate and making viewstate as small as possible.

How to setting values of InfoPath Textbox with jquery/javascript, json.


How to setting values of InfoPath Textbox with jquery/javascript, json.

Put this code in CEWP on a web part page containing an InfoPath Form Web Part.

Set delay, as InfoPath loads asynchronously, so document ready in jquery does not work.

window.onload = function()
{
    window.setTimeout(readyCall, 1000);
}

then get reference

  var textBoxEmployeeId = $("#ctl00_m_g_9053a19d_7ea2_49c3_9af1_11ab9e5bbca3_FormControl0_V1_I1_T2");
 
then call json endpoint

var url = "https://yourserver/endpoint?callback=?";
$.getJSON(url, null, function (data) {
textBoxEmployeeId.val(data["EmployeeNumber"]);
});

then set focus.  This is VERY import in InfoPath, or else it will not presist or preserve the data

textBoxEmployeeId.focus();

In InfoPath set the postback options of the field to NEVER

This way you can call json, or other web services, and write the values to InfoPath

How to hide the "Cannot be Blank" In InfoPath 2010, SharePoint Online


<style type="text/css">

.errorDiv
{
visibility:hidden;
     height:1px;
     overflow-y:hidden;
}
.errorDivClickable
{
visibility:hidden;
     height:1px;
     overflow-y:hidden;
}
</style>

Get all fields for XSLT webpart in SharePoint 2010




Place this in an xslt on the server, then link it in the dataview web part

 

       
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office">
<xsl:include href="/_layouts/xsl/main.xsl"/>
<xsl:include href="/_layouts/xsl/internal.xsl"/>
<xsl:template match="/">
   <textarea rows="20" cols="100">
       <xsl:apply-templates/>
   </textarea>
</xsl:template>
<xsl:template match="node()|@*">
   <!-- Copy the current node -->
       <xsl:copy>
       <!-- Including any child nodes it has and any attributes -->
       <xsl:apply-templates select="node()|@*"/>
   </xsl:copy>
</xsl:template>
</xsl:stylesheet>

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