Preview: Rare Solutions in SharePoint, C-sharp, ASP.Net, JQuery, SQL SERVER
SharePoint 2010, SharePoint, C-sharp, ASP.Net, JQuery, SQL Server SolutionsUpdated: 2012-02-08T00:33:24.610+05:30
Loop through all webs faster way in SharePoint 2010 2012-01-21T15:31:28.165+05:30 We are learning so many concepts each day and implementing/writing lot of code. But, we might not spending time to write the code more efficient way or more cleaner way. So, this post is again related to how to write code efficient in SharePoint 2010. :)So far, till SharePoint 2007 to loop through all the webs in site collection we use the code:using(SPSite site = new SPSite("http://sitecollectionurl"){foreach(SPWeb web in site.AllWebs){//Some code hereweb.Dispose();}}The above code is not at all wrong. Case 1:If you need the web object only for reading the generic information of the site like title, url, id etc… then it is a very expensive operation. For this, in SharePoint 2010 there is a workaround and that will load results 10 times faster than above code. Below is the efficient code:using(SPSite site = new SPSite("http://sitecollectionurl"){foreach(SPWebInfo webInfo in site.AllWebs.WebsInfo){//Code here to read web information }}This way you only reading the web information object instead of complete Web object. You can take a look more about WebInfo class here in MSDN. Case 2: If you want to read the properties you needed then there is a more better way than simply loop through AllWebs property in for each. The complete explaination is here. This is a very good post and very very faster way to read the properties in all webs. You really see the difference, a big difference. Do you like this post? [...]
Download Visual Studio 11 Developer Preview - now with SharePoint developer tools 2012-01-11T07:43:52.871+05:30 Visual Studio 11 Developer Preview is now available with the SharePoint developer tools and downloadable to public. Earlier version only has the Windows 8 stuff as a new thing along with some user experience improvements. But, in the new version it has the SharePoint developer tools added. So, as I am a SharePoint guy I would like to see what are all the features available in the new version. Visual Studio 11 is very fast when compared to Visual Studio 2010 and it definitely improves the productivity. This is one of the major point which I like about it. When come back to what are the new features added in SharePoint developer tools, below are the few of them.Create Lists and Content Types by Using New DesignersCreate Site ColumnsCreate Silverlight Web PartsPublish SharePoint Solutions to Remote SharePoint ServersTest SharePoint Performance by Using Profiling ToolsCreate Sandboxed Visual Web PartsImproved Support for Sandboxed Solutions.Support for JavaScript Debugging and IntelliSense for JavaScriptStreamlined SharePoint Project TemplatesRelated TopicsThe MSDN link has all these features explained. Stay tuned for the more updates from this blog as I like to publish more articles on what next... [...]
Script to install SharePoint 2010 in Windows 7 2011-12-12T21:50:08.761+05:30 You are ready to install SharePoint 2010 in Windows 7? Then you are at the right place. For the installation you have to download all required and follow the complete MSDN article and then execute step by step. If there is something which do all the steps for you then how it is? good right?
(image)
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.
How to find Inactive computer accounts in active directory? 2011-12-12T21:35:21.387+05:30 Do you know how can we do this? Either we query the AD to get the information by writing code in C# or manually check the AD for the inactive accounts. But, there is another simple way which will get this information without any big efforts. Yes, using Powershell script.
(image)
$COMPAREDATE=GET-DATEYou have to provide the days - the timeline of inactive accounts and where to save the output of inactive accounts list. The complete information is available at this post.
Open PDF files directly in browser SharePoint 2010 2011-12-12T14:27:43.521+05:30 Here is how you can tell SharePoint 2010 site to open the PDF files in the browser instead of prompting the user to save or open the PDF. This will be a great option to the most of end users. This needs simple Powershell scripting run on the server. Below is the code we should use:# <# # .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.It is taking the web application url as input And if the web application is not allowed the the PDF files MIME type to it's allow downloadable mime types collection then it will add it.So, once you run the code the files will be open up in the browser instead of prompting the user. The server will not allow PDF files by default as it think PDF files are not secure.Note: The script should run with the account who has FARM administrator level access.For more details about it: please check technet article. [...]
ASP.NET 4.5 new features 2011-12-04T20:04:35.429+05:30 The new version of ASP.NET 4.5 has many features integrated and there are many additions to the Visual Studio as well. I am really excited to see all of these features in hand.... These functionality improvements makes applications more easier and faster. The features are added in both Web forms and MVC.
(image)
ScottGu's blog has all these features explained in detail as series of posts. Readers, please read all of these and know the new and great features coming for better productivity. ASP.NET 4.5 New Features
Get TaskID in SharePoint custom Visual Studio workflows 2011-10-24T08:22:17.545+05:30 When you are working with custom workflows implementing in Visual studio, you might be sending the emails when a task is created. By default SharePoint sends an email when a task is assigned to a user. But, if you want to customize the email body and subject, then you will use send mail activity and will give link to the user. Here the problem starts. In CreateTask activity in Visual Studio you cannot get the taskID as the task is not yet created. What to do??? So, to get the task identifier we have to implement the below approach.CreateTask ActivityTaskCreated Activity SendMail ActivityOnTaskChanged ActivityTaskComplete ActivityRemember, until unless the Activity TaskCreated is executed the TaskID will not be available in workflow context. The main reason behind is, the task created information is not caught by SharePoint workflow anywhere until we run this activity. So, in the TaskCreated activity you can get the AfterProperties of the task and in those properties you will get the recent created task identifier which is integer. So, note that in custom workflows which are implementing through Visual Studio the only way you can get the TaskID is AfterProperties of the TaskCreated activity. I have wasted hours when I was learning these. Hope you liked it. [...]
The context has expired and can no longer be used–SharePoint and Reporting Services 2011-10-13T19:19:36.866+05:30 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. [...]
Close SharePoint 2010 Dialog through code 2011-10-08T17:03:46.746+05:30 In SharePoint 2010, the new feature is added is the dialog framework. With the help of this, user stays on the same page and able to get the information without go away from the current page. So, there are ways that we can close the dialog from the code in different ways. Below are the mainly used implementations in javascript and code behind.Javascript:The window.frameElement is the node which holds the current dialog window. commitPopup() method which commits the popup and closes the dialog from the page window. So, by simply calling the above method, the dialog window will close automatically.Code-Behind:HttpContext context = HttpContext.Current;if (HttpContext.Current.Request.QueryString["IsDlg"] != null){context.Response.Write("");context.Response.Flush();context.Response.End();}The dialog framework recognizes an additional parameter in the request named "IsDlg=1", which says open the page in dialog box. So, in code-behind simply check for query string parameter and if it exists then call the javascript method mentioned above by writing it to browser. So, when it executed the dialog will be closed. This is a very nice tip which helps in some custom implementations. Hope it helps. [...]
Exception of type 'System.Workflow.ComponentModel.WorkflowTerminatedException' was thrown 2011-10-08T17:00:11.531+05:30 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 Filter the logic by if, else and end the workflow. By throwing the exception from your code and by using the FaultHandler catch the exception and write it to logs. If we want to stop the workflow, we may write the code to stop the workflow by using CancelWorkflow(workflow). Even if you use the activity if you do not want to see the above exception in the workflow logs then you might do this. From the "Properties" window the attribute "Error" – fill this field with some text like "Workflow terminated as the reviewers not found for the current item" etc. So that user can understand the error clearly instead of the exception details. Hope it helps. [...]
Customize ReportViewerWebPart in C# for all SharePoint Zones 2011-09-23T16:34:33.042+05:30 This is one of the major milestone I have achieved recently to customize the report viewer web part for SharePoint sites. The issue I was facing: the SharePoint site which I have developed was too complex and it exposed via 3 zones. http://intranetsite, http://extranetsite, https://internetsitehttp://intranetsite – which is Windows based authentication site and for intranet people.http://extranetsite – Which is Windows based authentication site and for extranet peoplehttp://internetsite – Which is Forms based authentication site and for internet people.For each sub site in our implementation it should show the SSRS dashboard report of the site we are in which will contains all information of the site through reports. But, SSRS reporting services and report viewer web part has a limitation in SharePoint integration mode:System.Web.Services.Protocols.SoapException: The specified path refers to a SharePoint zone that is not supported. The default zone path must be used. ---> Microsoft.ReportingServices.Diagnostics.Utilities.SecurityZoneNotSupportedException: The specified path refers to a SharePoint zone that is not supported. The default zone path must be used.For example, you have added a report viewer web part to a SharePoint page. And when you opened the site in any other zones other than default zone then you will see above exception. So, how to solve this problem??? No way without customizing the default ReportViewerWebPart. So, I chosen this method and the implementation I have done is working very well.Implementation:Create a simple C# Project in Visual Studio to create a web part. The web part contains logic to render Report Viewer Web Part. The Report Viewer Web Part will take the default zone web url to render reports. Supply report parameters to the report viewer. Add any properties to the report viewer web part like toolbar mode, document map mode etc. CODE:public class CustomReportViewerWebPart : System.Web.UI.WebControls.WebParts.WebPart{#region Properties#endregion // Properties#region Constructorspublic CustomReportViewerWebPart(){this.ExportMode = WebPartExportMode.All;}#endregion // Constructors#region Privates//-----------------------------------------------------------------//Simple error handler for pre-render subs//-----------------------------------------------------------------private void HandleErrors(Exception ex){Page.Response.Write(ex.ToString());}#endregion // Privates#region Overrides//-----------------------------------------------------------------//Render this Web Part to the output parameter specified.//-----------------------------------------------------------------protected override void CreateChildControls(){base.CreateChildControls();try{ReportViewerWebPart wp = new ReportViewerWebPart();this.ChromeType = wp.ChromeType = PartChromeType.None;wp.PromptAreaMode = CollapsibleDisplayMode.Hidden;wp.ToolBarMode = ToolBarDisplayMode.None;string defaultZoneURL = ConfigurationManager.AppSettings["SharePoint_Default_Zone_URL"];if (string.IsNullOrEmpty(defaultZoneURL))defaultZoneURL = "http://defaultzoneurl";string reportPath = ConfigurationManager.AppSettings["SP_Report_Path"];if (string.IsNullOrEmpty(reportPath))reportPath = "reportpath"; //If it is the same report everywhere then use it. Otherwise create a web part property. So that user can input report path and use it here.string parameter1 = "parameter1 value"; if (!string.IsNullOrEmpty(defaultZoneURL)){if (defaultZoneURL.EndsWith("/"))defaultZoneURL = defaultZoneURL.Trim('/');wp.ReportPath = string.Format("{0}{1}", defaultZoneURL, reportPath);ReportParameterDefaultCollection parame = wp.OverrideParameters;parame.Add(new ReportParameter("Parameter1", parameter1)); //Add all report parameters here.Height = Unit.Pixel(1000);wp.Height = Height.ToString(); //If you [...]
Links for 2011-08-23 [Digg] 2011-08-24T00:00:00-07:00
e-Filing of Income Tax Returns online INDIA 2011-08-20T13:32:57.302+05:30 Yes, using the e-filing process one can file in tax returns just within a few clicks at any time of the day and that too without any hassles. Using this technology all you have to do is fill the form and submit it, online or offline.This is one of the best option available to us. It is very difficult to file for the income tax returns in regular process. Where as the e-filing process is simple and there is no need to dependent on anyone and you can do yourself with the required documents and information. The very first time you will face simple issue but it will be the nicer process once you get in. So, start using this feature and enjoy.How to file Income Tax ReturnsProcess of E-filing of tax returnsThe above links are quite enough to do what you are looking for. So, please use them to not miss to get your income tax returns. [...]
Set Page Layout programatically for a publishing page 2011-08-07T15:46:04.098+05:30 If you like to create pages in site through code then you have to set the page layout for the page. Below is the simple code which does that works well. 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. [...]
Set default Page Layout for a SharePoint site 2011-08-07T15:34:57.076+05:30 Before reading this post, please take a look at this post: Get default Page Layout for a SharePoint site.Setting default page layout to a SharePoint site is very important. For example if you are trying to create a new site/web template in SharePoint and from it you like to create sites then do not forget to set default page layout [especially in SharePoint 2010].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... [...]
Get default Page Layout for a SharePoint site 2011-08-07T15:18:18.911+05:30 Sometimes when you are provisioning sites through web/site templates you might miss one thing that setting default page layout for the web. In SharePoint 2010 especially you have to face this issue when you try to browse to the page "Page layouts and Site Templates" from site settings page. If there is no default page layout then there are problems while creating new page as well. So, this could be a major issue in some special cases.Sometimes you might get the error like "Data at the root level is invalid. Line 1, position 1" because of this.So, we have to know is there any default page layout set for the site and below is the perfect console application solution for it. 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. :) [...]
Copy users from one SharePoint group to another group 2011-09-06T22:26:12.883+05:30 This is one of the question raises from many people who has to copy users from one SharePoint group to another group. There is no direct way you can directly copy users through browser. So, it could be problem to site owners and administrators to add all users again. How to solve these kind problems?Here are some scenarios of why it is actually needed?There are so many SharePoint groups in the site and need to copy the users from one group to another group.Two sites needed same permissions and one site group permissions need to copy to another group.So, from the ways I know below are the possibilities.Create a simple console application and write logic to copy users.Use the simple option which is available through browser.Go to Site Settings of the site.Click on People and Groups.Go to the group from which you want to copy users.From the group page, select all users and then from Actions Menu, choose "Email Users" as shown below. Once you selected "E-Mail Users" then your default email program (Ex: Outlook) will be open with all email addresses.Select all email addresses and copy them.Go to SharePoint site and then go to SharePoint group to which you want to add users.From the toolbar, select "New" and then "Add Users". From the add users page, paste all email addresses and then click "Check names" icon for validation.Click OK button to save the changes.With the process above, we have successfully completed the copying of users from one group to another group. Love to hear any comments on it. [...]
Activate only selected features while deploying a solution package in Visual Studio 2010 2011-09-08T20:52:50.128+05:30 In Visual Studio 2010 SharePoint Developer Tools is what we use to develop quick solutions to SharePoint. With these tools we can quickly deploy into SharePoint environment as well. But, the only issue we see here is, if we are trying to deploy a package which contains a set of 5 features then all of them will be activated by default. But, this might not be a valid behavior for us. We need to activate only 3 features while deploying the package and the other 2 features need to be installed into SharePoint but should not be activated. So, this is not available by default in the SharePoint Development Tools in Visual Studio 2010.Recently when I was browsing in internet for this, how to deploy only selected features into SharePoint, but not all and found a great Visual Studio 2010 Extension. Which is a great tool to use and works perfect. Download the extension here.Once you get his extension, directly run it by double clicking on it. Before you see the changes, close any existing Visual Studio instances and reopen them. The extension will be added to Visual Studio 2010 and ready to use. But, to use it in your SharePoint project, you need to do one more exercise.When you right click on your SharePoint project you will see a new entry in the menu item as shown below. Before you start using it, right click on the project and select "Properties". From the "SharePoint" tab, click on the New button to add "Active Deployment Configuration" as shown in figure. From the "Active Deployment Configuration" drop down, select the new configuration we just created. The configuration is same as others but the only extra action here is "Activate selected features" custom extension. Now, we are ready to use this feature. Right click on project, select "Select Features to activate…" and you will be open up with a window as shown below. Now, you can build and deploy, you will see only the selected features will be activated only. What a nice feature, I really need it in almost all the times. Thanks to Mavention for the great VS extension. [...]
Permissions for document 'Move' operation in SharePoint 2011-07-16T12:12:20.103+05:30 This might not be a super thing to blog but very important point to note. Through code I have tried to move a document from one document to another document by using file.MoveTo() operation. It was working very fine when I tested as I am administrator in the dev environment. But, when I have given to QA for testing it was failing. I have tried so many combinations of giving different access to them and nothing worked. When I have given them either Owners or site collection administrator access it started working. So, I was not understanding of what was the permission level do they need? After tried different combinations of permission levels to them one matched and worked perfect. That was Contribute and Approve permission levels. So, for the logged in users who don't have both of these permission levels the code is failing for them and the result file was not moving successful. [Another note is, I am using publishing site with auto approval of document in document library.]Code used: 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.I am thinking it is correct according to my analysis and research. Please let me know if something is wrong in this post or any better solutions. [...]
Move and Copy operations in SharePoint Lists 2011-07-16T11:51:02.909+05:30 Do not know how many of you aware of these important points.
How to hide a specific div in SharePoint 2010 dialog 2011-07-16T11:49:40.468+05:30 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. (image)
Upgrade SharePoint 2007 Visual Studio projects to 2010 2011-07-02T14:59:05.914+05:30 This will be very helpful for the scenarios where we have custom solutions developed in Visual Studio 2008 for SharePoint 2007 environment and upgraded 2007 site to SharePoint 2010 and now in SharePoint 2010 we like to do some changes to that custom solution files. Simply, we have a SharePoint 2007 site upgraded to SharePoint 2010 and then it has some custom solutions developed like web parts, solution packages, features etc. Now, we are in SharePoint 2010 environment and like to extend the custom web parts, features from the earlier version of SharePoint. So, we need some sort of support to migrate our SharePoint Visual Studio projects from Visual Studio 2008 to Visual Studio 2010 to deploy to SharePoint 2010. I believe you all are clear till this point.Get the tool here. http://archive.msdn.microsoft.com/VSeWSSImport/Release/ProjectReleases.aspx?ReleaseId=4183It is simple project and when you build it, you will get executable and installs template to Visual Studio. But, the only preliminary requirement here is, you have to install Visual Studio 2010 SDK to open project.Once everything is ready, you will see a new template named "Import VSeVSS project" under new project category. Here you go..... [...]
SharePoint workflow staus codes 2011-07-02T14:20:15.968+05:30 This is very important for SharePoint devs. Even I have used them many times, but I forget the status codes almost every time. So, might be happening to everyone too and planned to blog in my blog.The enum SPWorkflowStatus in the namespace "Microsoft.SharePoint.Workflow" in the library "Microsoft.SharePoint" is what we have to use for these status codes. 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 Hope this is enough for us to get what we needed. :) [...]
Error occurred in deployment step ‘Recycle IIS Application Pool’: The communication object, System.ServiceModel.InstanceContext, cannot be used for communication because it has been Aborted 2011-07-02T11:44:15.077+05:30 When we are developing custom code through Visual Studio 2010 for SharePoint 2010 sites and when we try to deploy the solution then we might see below error."Error occurred in deployment step ‘Recycle IIS Application Pool’: The communication object, System.ServiceModel.InstanceContext, cannot be used for communication because it has been Aborted."When I see this very first time and did not get any clue of what it is looking for and why it is not able to communicate to SharePoint sites. After some time, I though of doing some combinations and all failed in deploying the custom piece to SharePoint. Solution:Sometimes when I do rebuild the project and didn't hit "Package" and deploy directly from Visual Studio it successful. If it is not successful then the only way is RESTART your visual studio. Frustrated? Yes, me too. But there is no way I found. [...]
Get bytes from Stream in c# 2011-05-19T20:59:59.773+05:30 I know you may think what is the need of this post as this is very minor or simple to think and write. But, whenever I need to get bytes from a stream object, I always forgot it. This is simple but most of the times we used to Google. So, planned to write it to remember at least myself next time.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(); } } [...]
Check list exists in SharePoint site 2011-05-19T20:35:29.911+05:30 This is very generic issue all SharePoint developers face at initial stages. As there is no default method available in SharePoint API to check whether if list exists in the SharePoint site, everyone write the below code: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. [...]
Links for 2010-09-02 [Digg] 2010-09-03T00:00:00-07:00
Links for 2010-08-26 [Digg] 2010-08-27T00:00:00-07:00
Links for 2010-08-23 [Digg] 2010-08-24T00:00:00-07:00
Links for 2010-08-17 [Digg] 2010-08-18T00:00:00-07:00
Links for 2010-08-13 [Digg] 2010-08-14T00:00:00-07:00
Links for 2010-07-29 [Digg] 2010-07-30T00:00:00-07:00
|
|||||||||||||||||||