Tuesday, June 4, 2013

Call powershell from batch file

Here is the small example of how to call powershell script file from batch file.

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -command "< Path of your ps1 file>"

NOTE : Here you need to put -command , If not batch file will just load the ps1 file will not execute.



PowerShell cannot be loaded because the execution of scripts is disabled on this system

Here is the error which you will face when you run powershell first time on any new envrionment.

By default execution policy for powershell will be disabled in any server. This can be enabled through script property.

Run Powershell as administrator and type

Set-ExecutionPolicy Unrestricted
Thank you !!

C# code to get the count of files in sharepoint list

Here is a simple console application. Which will loop through the all the lists.

This console loop through all the items in the list and fetch the count of files are attached to the list.

Here is the peace of code :
foreach (SPList list in listColl)
           {
                                        
if (list.BaseTemplate == SPListTemplateType.GenericList || list.BaseTemplate == SPListTemplateType.Links || list.BaseTemplate == SPListTemplateType.Announcements)
{
if (list.EnableAttachments)
{

int ItemCount = 0;
foreach (SPListItem item in list.Items)
{
if (item.Attachments != null && item.Attachments.Count > 0)
{
foreach (var attachment in item.Attachments)
{
 sAttNames.Append(attachment.ToString());
}
ItemCount += item.Attachments.Count;
}
}
}
}
}

Tuesday, May 7, 2013

Sharepoint list definition check if already exists

Here is the article on how to check if a list is already exists or not before you create any list using list definition from sharepoint If you create list definition from VS and deploy it, For every deploy it will delete the list if already exists.

To aviod that we need to modify the SharePointProjectItem.SPDataItem file in VS

Just set "DeploymentConflictResolutionBehavior" to "None" will stop deleting the list eventhough if exists

Here is the sample XML code..


  
    
  
  
    
  





Thank you !!



Anchor tags not working in firefox



Here is the simple issue fixed when working with HTML. This is kind of a browser compatibility issue.

In my sharepoint page we have created a CEWP and placed some HTML code along with anchor tag bookmarks features.

But Book marks is working fine in IExplorer and not working in Firefox.

This got fixed by removing the "#" from the name of the Div tag name of the Bookmark.



Thank you !!

Hide ribbon in sharepoint

Hi

With small css property you can hide the ribbon control in sharepoint

Here is the code for that

 



Just put the above code in master page of the sharepoint site..



Thank you !!

visual studio 2012 assembly



While starting with new sharepoint applications with framework 4.0 or 4.5

After you create and deploy any new sharepoint application. You cannot see the DLL to be deployed to

%WINDIR%\assembly\

For all the framework 4.0 and more DLL's will be deployed to the new location

%WINDIR%\Microsoft.NET\assembly\

The reason behind this is the older version framework till 3.5 are using by CLR 2.0 and from 4.0 it got converted to CLR 4.0 version.

Multiple CLR cannot do compilation from the same location of assemblies

That is why this change happened...