Friday, January 14, 2011

Hello World Webpart

Select New Project… from the Startup page to display the New Project dialog box. Expand the SharePoint node and select 2010 to display the available project templates, as shown in Figure 1.
Figure 1: Available project templates


Visual Studio 2010 offers templates to support the most common SharePoint development projects. Select the Visual Web Part template and click OK to start the SharePoint Customization Wizard. The wizard prompts you for the URL of the SharePoint site to be used for deployment and debugging and lets you choose between farm and sandboxed solution types.
Farm solutions deploy to the SharePoint farm and have full access to the SharePoint API and all SharePoint resources. In contrast, sandboxed solutions deploy to the site collection, have limited access to the SharePoint API, and can only access data within the site collection. This lets farm administrators allow sandboxed solutions, which won't impact the entire farm, to be deployed to the server. Visual Web Parts can be deployed only in farm solutions, so the sandboxed option isn't available in this case.
After you create the project, the Visual Web Part opens in the default Source view. Click the Design tab to switch to a WYSIWYG view. Regardless of which view you prefer, you can drag and drop controls from the toolbox onto the designer.
Now I'll build a typical "Hello World" Web Part. Click the designer near the top and type "My Hello World Web Part." You'll notice you have all the text tools, such as font size and color, in the menu. Under the text, drag a label and button control onto the designer. Figure 2 shows what the designer will look like so far.
Figure 2: The designer so far

Double-click the button to display the code behind the form. Add a using directive to access the SharePoint object model (a reference to the Microsoft.SharePoint.dll assembly is included in all SharePoint projects).
using Microsoft.SharePoint;

Next, add the following code to the button event handler Button1_Click. This code gets the current user for the SharePoint site and sets the label to the LoginName.

SPUser user = SPContext.Current.Web.CurrentUser;
Label1.Text = user.LoginName;

With the code now complete, set a breakpoint in the first line of the event handler. It's time to deploy the Web Part and check whether it works as expected. Press F5 to instruct the project system to build the assembly, package the feature, and deploy the solution to the SharePoint site. In addition, the debugger will be attached and the browser will launch to display the SharePoint site.
When the browser launches, you're taken to the home page of the site you specified during project creation. Click on the Site Actions menu at the top left of the page, and choose More Options. In the dialog page that appears, select the item Web Part Page and click Create. Enter HelloWorld as the Name, and leave the Layout Template selected as the default. Change the Document Library to Shared Documents and click the Create button. In the header section of the new page, click Add a Web Part to display the Web Part picker. In the Categories section, select Custom, and in the Web Parts section select the Web Part VisualWebPart1. Click the Add button to add the Web Part to the page, and then click the Stop Editing button on the SharePoint ribbon. Figure 3 shows the Web Part displayed on the HelloWorld page in the browser.
Figure 3: The HelloWorld page

Issue(can be encountered)

Error : 
image

Solution:
For example, you may consider custom document library to store the images for your solution, etc.
However, sometimes we need to get rid from sandboxed solution. Then we need to change the project type into non-sandboxed solution. To change project type to non-sandboxed solution,
1. Click on project property
2. Set Sandboxed Solution = False.
image





Sunday, January 9, 2011

SharePoint 2010 - Best Practices Document: Document Library


These are the things you really must do for every document library:
  1. Require Check Out on any document library where multiple users might make changes.
    • Check out is supported by, but not enforced on, document libraries unless you make it that way!
  • Add the Checked Out By column to the default view of the library.
    • Those way users can see easily who has a document checked out. If you hover over the Checked Out icon, it tells you in a tip, but that's not exactly a "discoverable" little gem.
  • Train users how to check out, check in, and discard check out.
    • Be sure they understand that the changes they make can't be seen by other users until checked in.
    • Do they understand the purpose of Keep document checked out after checking in? They check in the document to make their changes visible, but maintain an editorial lock to make more changes.
    • If there is a required column (property/attribute/metadata) that's blank, the document can't be checked in. Train users how to deal with this. This is particularly challenging if you're using Internet Explorer (IE) to upload documents. You can upload them, but they won't be visible to others until checked in, and they can't be checked in until required columns are complete. So after uploading, open the SharePoint document library in IE and fill in those columns! What solutions have YOU found in your organization to this problem? I've yet to uncover a really great answer. DO YOU HAVE ONE?
  • Create a permission level that gives someone the Override Checkout permission.
    • Take the burden off of yourself and your IT team to check documents in when users forget to do so before going on vacation.
    • Train your "check in managers" and your users so that they know what it means when a document has been checked in "on behalf" of someone else. If that someone else was using Microsoft Office 2007's SharePoint Drafts folder, there are likely to be changes in the local copy of the document that were not included when the document was checked in. At some point, the two versions (the server's copy and the user's local copy) will need to be reconciled.
  • Decide whether to use versioning.
    • If you want to restrict who can see drafts, use minor versions. Most of the time your processes will require that. If not, there's no real point in using minor versions.
  • If you're using versioning, set retention limits.
    • By default, SharePoint keeps all versions, and these aren't bitwise differential versions—they're the full version. With large documents, even a small but active library can eat up your database in a hurry!
  • Configure views that will help users navigate libraries effectively and find the documents they require.
    • Use folders only if you need to scope unique permissions on documents or if you need to make a subset of documents easily offline-able by Microsoft Outlook.
    • If your library has more than 2,000 items, be sure you remove the out-of-the-box default view, which shows all items. Add views with filters so that no view returns more than 2,000 items. Paging and grouping doesn't count. You must use a filter. (BTW, in its sneak peek of SharePoint 2010, Microsoft announced that SharePoint 2010 will have large-list support, so this won't need to be done much longer.)
Then there are things that take a bit more time and configuration but really pay off:
  1. Create content types for documents that belong in a library, and upload a template for that document into the content type. Users can then click the NEW button on the library, choose the document type, and a new document with the right template appears.
  2. Push navigation aids to users: Add Favorites to users' Internet Explorer (Group Policy Shortcut Preferences) and Network Places (XP) or Network Locations (Vista), which can be created by an administrator (separately for XP and Vista), uploaded to file shares, then distributed by copying into users' systems (%userprofile%\nethood in XP and %appdata%\Microsoft\Windows\Network Shortcuts in Vista).
  3. Integrate custom columns (metadata) into Microsoft Word 2007 documents using Quick Parts. You can "link" content in your document with SharePoint metadata.

Wednesday, January 5, 2011

SQL - to call a sp in another sp


Inside your procedure X you can do something like :

"EXECUTE PROCEDURE Y (ID) RETURNING_VALUES RESULT;"

but you can store all the code from your procedures into one using IF :

" IF (X1 HAPPENS) THEN
EXECUTE PROCEDURE Y(ID)
ELSE IF (X2 HAPPENS) EXECUTE PROCEDURE Z(ID)
ELSE IF (X3 HAPPENS) EXECUTE PROCEDURE W(ID);