Yah! there is a great script which is written by Ram which installs SharePoint 2010 on windows 7 PC. Go and download and execute guys. Great script.
Get the information here.
$COMPAREDATE=GET-DATE $NumberDays=90 $CSVFileLocation='C:\TEMP\OldComps.CSV' GET-QADCOMPUTER -SizeLimit 0 -IncludedProperties LastLogonTimeStamp | where { ($CompareDate-$_.LastLogonTimeStamp).Days -gt $NumberDays } | Select-Object Name, LastLogonTimeStamp, OSName, ParentContainerDN | Sort-Object ModificationDate, Name | Export-CSV $CSVFileLocationYou have to provide the days - the timeline of inactive accounts and where to save the output of inactive accounts list.
# <# # .DESCRIPTION # This script adds new MIME type to "AllowedInlineDownloadedMimeTypes" property list of defined SharePoint 2010 Web Application. # # Script prompts you for MIME type and Web Application URL. # # Code shall run in context of Farm Administrators group member. # # .NOTES # File Name : Add_MIME_Type.ps1 # Author : Kamil Jurik, WBI Systems a.s. # Created : 11/12/2011 # If ( (Get-PSSnapin -Name "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } Get-SPWebApplication $WebApp = Get-SPWebApplication $(Read-Host "Enter Web Application URL") Write-Host "Mime Type Examples:""application/pdf, text/html, text/xml" If ($WebApp.AllowedInlineDownloadedMimeTypes -notcontains ($MimeType = Read-Host "Enter a required mime type")) { Write-Host -ForegroundColor White "Adding" $MimeType "MIME Type to defined Web Application"$WebApp.url $WebApp.AllowedInlineDownloadedMimeTypes.Add($MimeType) $WebApp.Update() Write-Host -ForegroundColor Green "The" $MimeType "MIME type has been successfully added." } Else { Write-Host -ForegroundColor Red "The" $MimeType "MIME type has already been added." }The powershell script do the magic for us. Below is the explanation.
Error:
"System.Web.Services.Protocols.SoapException: Report Server has encountered a SharePoint error. ---> Microsoft.ReportingServices.Diagnostics.Utilities.SharePointException: Report Server has encountered a SharePoint error. ---> Microsoft.SharePoint.SPException: The context has expired and can no longer be used. (Exception from HRESULT: 0x80090317) ---> System.Runtime.InteropServices.COMException: The context has expired and can no longer be used. (Exception from HRESULT: 0x80090317) --- End of inner exception stack trace --- at Microsoft.ReportingServices.WebServer.ReportingService2005Impl.GetDataSourceContents(String DataSource, DataSourceDefinition& Definition) at Microsoft.ReportingServices.WebServer.ReportingService2006.GetDataSourceContents(String DataSource, DataSourceDefinition& Definition)"
Solution:
This was coming completely due to the sever clock has wrong time set. So, by adjusting the time on the server solved the problem.
Special thanks to "Steve Mann" for finding the solution. It is a great find as it is just by guessing and thinking in different ways. Good one Steve.
HttpContext context = HttpContext.Current; if (HttpContext.Current.Request.QueryString["IsDlg"] != null){ context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>"); context.Response.Flush(); context.Response.End(); }
This is the error you see when you use the TerminateActivity in Windows workflow foundation/Visual Studio workflow development for SharePoint applications. The main reason behind why this exception is "We are terminating the current running workflow in middle and framework rises the exception that the workflow is terminated".
The main use of this TerminateActivity is for terminating workflow only. But, I do not recommend to use this activity in your workflows as this is a kind of exception which is throwing by WWF framework. Instead we could try
Hope it helps.
private static void SetPageLyoutToPublishibPage() { using (SPSite site = new SPSite("http://SP2010Site")) { using (SPWeb web = site.OpenWeb()) { PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); PageLayout pageLayout = null; foreach (PageLayout p in publishingWeb.GetAvailablePageLayouts()) if (p.Name.Equals("BlankWebPartPage.aspx", StringComparison.InvariantCultureIgnoreCase)) { pageLayout = p; break; } PublishingPage page = publishingWeb.GetPublishingPage(web.ServerRelativeUrl + "/Pages/Default.aspx"); page.CheckOut(); page.Layout = pageLayout; page.Update(); page.CheckIn(""); } } }Any issues, please post it here.
private static void SetDefaultPageLayout() { using (SPSite site = new SPSite("http://SP2010Site")) { using (SPWeb web = site.OpenWeb()) { PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); PageLayout pageLayout = null; foreach (PageLayout p in publishingWeb.GetAvailablePageLayouts()) if (p.Name.Equals("BlankWebPartPage.aspx", StringComparison.InvariantCultureIgnoreCase)) { pageLayout = p; break; } publishingWeb.SetDefaultPageLayout(pageLayout, true); publishingWeb.Update(); } } }Here, I have set the Blank Web Part page as the default page layout to the SharePoint site. This way you can control the logic as your wish...
private static void GetDefaultPageLayout() { using (SPSite site = new SPSite("http://SP2010Site/")) { using (SPWeb web = site.OpenWeb()) { PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); PageLayout pageLayout = publishingWeb.DefaultPageLayout; Console.WriteLine(pageLayout.Name + "Url : " + pageLayout.ServerRelativeUrl); } } }So, this way you can trace easily some kind of problems which create problems to us. :)
SPFile file = currentItem.File; file.MoveTo(filePath, true);For a document move operation the logged in user should need both Contributor and Approve permission levels for publishing web sites in SharePoint.
Do not know how many of you aware of these important points.
The class in styles "s4-notdlg"[means don't show in dialog not+dlg] is what we have to use to not show a specific division on SharePoint 2010 dialog.
For example, there is a banner in the header position of the master page and you do not want to show the banner in the dialog then the only simple option for you is using a simple css class to your banner div. If you add this class to your banner then when no dialog on the page no change to your implementation but when you are on dialog then the division with the class "s4-notdlg" will be forcibly applied to "display:none".
So, the moral of the story it is a good tactic that Microsoft SharePoint team developed to solve some major issues in design on dialogs.
0 | NotStarted | Not Started |
1 | FailedOnStart | Failed On Start |
2 | InProgress | In Progress |
3 | ErrorOccurred | Error Occurred |
4 | StoppedByUser | Cancelled |
5 | Completed | Completed |
6 | FailedOnStartRetrying | Failed on Start (retrying) |
7 | ErrorOccurredRetrying | Error Occurred (retrying) |
8 | ViewQueryOverflow | -- |
9-14 | Unknown | Unknown |
15 | Cancelled | Cancelled |
16 | Approved | Approved |
17 | Rejected | Rejected |
public byte[] GetBytesFromStream(Stream stream) { byte[] buffer = new byte[16 * 1024]; using (MemoryStream ms = new MemoryStream()) { int read; while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } return ms.ToArray(); } }
SPList list = web.Lists["Task List"]; If(list != null) { //Some code on list. }This is not correct to code like this. We all know generics and collections in c#. SPWeb.Lists is a collection and if you want to get one object from collection either we need to pass index or the key. If that didn’t find in the collection it gives us the exception. So, in our example if the Sharepoint site don’t have list named “Task List” then you will give run time exception in the line 1 itself. So, there is no point of checking whether list object is null. So, here is where many people stuck at. As Lists is plain collection object there is no other way of checking for the list exists in collection other than below.
private static bool ListExists(SPWeb web, string listName) { try { SPList list = web.Lists[listName]; } catch { return false; } return true; }I know what you are thinking [Is this solution right?]. Yes, unfortunately there is no other way. So, we have to use this to check whether list exists in a SharePoint site.
private void DeleteEventReceiverFromAList(string siteUrl) { using (SPSite site = new SPSite(siteUrl)) { using(SPWeb web = site.OpenWeb()) { try { SPList list = web.Lists["myList"]; if (list != null) { string className = "EventReceiverClass"; string asmName = "EventReceiverAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a865f0ecc234ea51"; web.AllowUnsafeUpdates = true; int receivers = list.EventReceivers.Count; bool isAddedReceiverExist = false; bool isUpdatedReceiverExist = false; for (int i = 0; i < receivers; i++) { SPEventReceiverDefinition eventReceiver = list.EventReceivers[i]; if (eventReceiver.Class == className && eventReceiver.Type == SPEventReceiverType.ItemAdded) { eventReceiver.Delete(); break; } } } } catch { } finally { web.AllowUnsafeUpdates = false; } } } }In this code also, there is nothing to explain very detail. Please let me know if you have any questions.
private void AddEventReceiverToAList(string siteUrl) { using (SPSite site = new SPSite(siteUrl)) { using (SPWeb web = site.OpenWeb()) { try { SPList list = web.Lists["myList"]; if (list != null) { int receivers = list.EventReceivers.Count; string className = "EventReceiverClass"; string asmName = "EventReceiverAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a865f0ecc234ea51"; web.AllowUnsafeUpdates = true; bool isAddedReceiverExist = false; for (int i = 0; i < receivers; i++) { SPEventReceiverDefinition eventReceiver = list.EventReceivers[i]; if (eventReceiver.Class == className && eventReceiver.Type == SPEventReceiverType.ItemAdded) { isAddedReceiverExist = true; break; } } if (!isAddedReceiverExist) list.EventReceivers.Add(SPEventReceiverType.ItemAdded, asmName, className); } } catch { } finally { web.AllowUnsafeUpdates = false; } } } }This is very straight forward code and hope you got it.
private void ChangeOrHideContentTypesInALibrary(SPList list) { list.ContentTypesEnabled = true; SPFolder folder = list.RootFolder; List<SPContentType> orderedContentTypes = new List<SPContentType>(); foreach (SPContentType ct in folder.ContentTypeOrder) { if (ct.Name.Contains("ContentType1") || ct.Name.Contains("ContentType2")) orderedContentTypes.Add(ct); } folder.UniqueContentTypeOrder = orderedContentTypes; folder.Update(); }
private void AddContentTypeToLibraries(string siteUrl) { List<SPContentType> contentTypes = new List<SPContentType>(); using (SPSite site = new SPSite(siteUrl)) { using (SPWeb web = site.OpenWeb()) { contentTypes.Add(web.ContentTypes["ContentType1"]); contentTypes.Add(web.ContentTypes["ContentType2"]); contentTypes.Add(web.ContentTypes["ContentType3"]); } foreach (SPWeb web in site.AllWebs) { try { web.AllowUnsafeUpdates = true; foreach (SPList list in web.Lists) { if (!list.Title.Equals("MyList", StringComparison.InvariantCultureIgnoreCase)) continue; for (int i = 0; i < contentTypes.Count; i++) { AddContentTypeToList(contentTypes[i], list); } } } catch { } finally { web.AllowUnsafeUpdates = false; web.Dispose(); } } } } void AddContentTypeToList(SPContentType ct, SPList list) { if (list.ContentTypes[ct.Name] == null) { list.ContentTypes.Add(ct); list.Update(); } }The first method is what we are looping through all webs and go to each list and try to add a content type. And the second method is before adding a content type to a list, we are checking whether the content type is already there or not for that list. So, we are checking for that condition and if find the content type is not already attached to the list then only we are adding to the list.
//Get the connection details by connection name AdoQueryConnection adoConnection = (AdoQueryConnection)DataConnections["Get_User_Details"]; if (adoConnection != null) { string orgCommand = adoConnection.Command; //To read original command int index = orgCommand.IndexOf("DEFAULT"); //Find where the keyword "DEFAULT" in the command string string SPROC = string.Empty; if (index > -1) { try { SPROC = orgCommand.Substring(0, index); //Get only the SPROC name. adoConnection.Command = string.Format(SPROC + userName + "'"); //Append user name to the query. adoConnection.Execute(); //Execute the final query. This is what the command which contains actual parameter value instead of DEFAULT string. } catch { } finally { adoConnection.Command = orgCommand; //Should not forget to write this. We have to do this. } } }Things to note:
This is what I want to post as I heard so many people are facing this issue. We can use variables in T-SQL queries but, there are requirements that we may select only the top 5 rows or 10 rows or n rows from the result set and use them wherever needed. So, below is the implementation we have to use to achieve that.
I do not think the first way is feasible. So, I prefer to go to second way and below are the implementation details.
SQL SERVER 2005:
DECLARE @TOP INT;
SET @TOP = 10;
SELECT TOP (@TOP) * FROM [User]
If you observe the variable is what storing the value of how many values we need to select. from the table And the last statement is what the final query which does what we needed. Remember the brackets () around the @TOP variable are what must and should. I also failed to write the query very first time as I forgot to place the brackets around the @TOP variable.
Earlier Versions: SQL SERVER 2000:
DECLARE @TOP INT;
SET @TOP = 5;
SET ROWCOUNT @TOP;
SELECT * FROM [User];
SET ROWCOUNT 0; --DO NOT FORGET TO WRITE THIS. VERY IMPORTANT
There is nothing tricky here. Just setting the ROWCOUNT internal variable to the required value is what works for us. And the very important thing is do not forget to reset the value of ROWCOUNT back to 0. Otherwise it effects the other result sets which comes after these T-SQL statements.
I think you got what I am trying to say here and enjoy the nice tips and posts.This is very needful post. Most of the times in general development we work on class library projects which outputs DLL at the end. To use them we may need to know the Public Key Token of the DLL and use it wherever needed. We can know the Public key token either through the command prompt SN.EXE or by deploy it to GAC. But, what if you have some tool available and displays the Public key token within Visual Studio?
That’s it. This is very helping one to me. Hope you also like it. Reference