Wednesday, April 20, 2011

Where all do we need to update the new address when we move.

U.S. Postal Service: To Forward Your Mail

• Change your address online for a $1 fee if you have a credit card and valid e-mail address. You can also print the form and then mail or deliver it to your local post office to change your address for free. After changing your address, the U.S. Postal Service will forward your mail to your new address for up to one year.
https://moversguide.usps.com/

Other Federal Agencies

• Internal Revenue Service – Change your address with the IRS if you are expecting a tax refund or other mail.
Social Security Administration – Change your address online if you receive Social Security disability, retirement, or survivors benefits.
Social Security Administration: Supplemental Security Income Benefits – If you receive Supplemental Security Income benefits, you must call 1-800-772-1213 or visit a local office within 10 days after the month the change occurs.
Department of Veterans Affairs – Learn how to change your address if you are a veteran who receives benefit payments or you wish to update your medical enrollment and/or records.
U.S. Customs and Immigration Services – If you are a non-U.S. citizen who is required to register with USCIS, then you need to let them know if you move.

State Agencies
Driver's License – Contact your state if you need to change your address on your driver's license or motor vehicle registration.
Voter Registration – Contact your state's election office if you want to change your address on your voter registration record.
Other
•Your car insurance provider
•Family insurance provider
•Employer
 •notify your apartment rental office where you stay for any future communication.
•online accounts like googleadsense, ebay & Amazon etc.



Tuesday, April 19, 2011

Sand boxed development in Visual studio 2010


After my initial search, i thought it's good to remember few things about sandbox solutions
The facts about Sand boxed development 

A new feature in SharePoint 2010, called sandboxed solutions, helps enabling farm administrators to feel comfortable that the SharePoint farm is safe, giving site collection administrators the authority to manage the applications in their site collection, and providing developers with the flexibility to create solutions they know will be deployed in a safe and rapid manner.

The structure of a sandboxed solution is very similar to a farm solution, which generally runs with full-trust permissions. The main differences lie in how a sandboxed solution is deployed and in the process that hosts the solution (which determines whether a solution is a sandboxed solution or a farm solution). This means that the same sandboxed solution can run with full trust when it’s deployed at the farm level and with partial trust when it’s deployed at the site collection level.
A SharePoint solution is a deployable package that can contain features and assemblies. The solution package is a .cab-based file with a .wsp extension. Visual Studio 2010 SharePoint project templates create .wsp package files. A solution might contain a number of SharePoint features, and these features provide functionality such as Web Parts, list definitions, modules, and event receivers.

When we open .package file in a sandboxed solution in Microsoft Visual Studio 2010 it shows that the global assembly cache is the deployment target of assemblies. But actually it is not stored in GAC or in file system.

 Actually, the sandbox process prevents accessing data outside the site collection where the solution has been deployed. This means, the following operations are not allowed in a sandbox framework 
• We can’t access the Internet to make Web service calls.
• We can’t access a hard drive to read or write files.
• We can’t access code that is not marked to allow partially trusted callers.
• We can’t deploy files to disk or add assemblies to the GAC in a sandboxed solution.
• We can't do any security-related functionality, such as running RunWithElevatedPriviledges and other SPSecurity methods, is not allowed.
• We cannot deploy a visual web part using sandbox framework.
The assemblies in a sandboxed solution are included in the solution package (.wsp file), and the package is deployed to the site collection's Solutions Gallery. [Site Actions /Site Settings/ Galleries section/Solutions]. When a sandboxed solution is accessed for the first time, such as when a user navigates to a page that contains a Web Part from a sandboxed solution, any assemblies in the solution are extracted from the package in the gallery and copied to the file system of the server that is handling the sandboxed request. The default location is C:\ProgramData\Microsoft\SharePoint\UCCache; however, this is configurable on each server that is running the User Code Host Service, which is called the Microsoft SharePoint Foundation Sandboxed Code Service in the user interface of the Central Administration application. The executable of this service is SPUCHostService.exe. The server that handles the sandboxed request is not necessarily the front-end web server that is handling the initial HTTP request: The Microsoft SharePoint Foundation Sandboxed Code Service can be run on back-end application servers in the farm instead. Because the sandboxed user process (SPUCWorkerProcess.exe) cannot copy anything to the file system, the copying is done by the Microsoft SharePoint Foundation Sandboxed Code Service.
The assemblies of a sandboxed solution do not stay in the file cache perpetually. When the user session that accessed the solution ends, the assemblies stay in the cache for only a short time, and they may be reloaded from there if another user session accesses them. Eventually, if they are not accessed, they are removed in accordance with a proprietary algorithm that takes into account how busy the server is and how much time has gone by since the assemblies were last accessed. If the sandboxed solution is used after that time, the assemblies are extracted again and copied to the UCCache.

Debugging

We all know how to debug in full-trust solutions, which run under the IIS worker process used by SharePoint called w3wp.exe. Surprisingly, Sandboxed solutions do not run under this process. They run under the sandboxed worker process called SPUCWorkerProcess.exe, VS2010 automatically attaches the debugger to this process when we press F5. If a solution that’s already deployed we need to attach to this process manually.

MS Best practices says
  • Avoid Creating Static Members 
  • Avoid Throwing Unhandled Exceptions 
  • Use Both the AllowPartiallyTrustedCallers Attribute and the SharePointPermission Attribute
What can be implemented in sandboxed solution?
Assembly
content types
event receivers
Feature
Feature receivers
Web parts
Field
Read more..

Things not allowed in sanboxed development
 - Read..

Tuesday, April 12, 2011

Using Disposable Windows SharePoint Services Objects

Using Disposable Windows SharePoint Services Objects
We can employ certain coding techniques to ensure object disposal. These techniques include using the following in your code:
  • Dispose method
  • using clause
  • try, catch, and finally blocks 
Dispose vs. Close Method Usage
The Dispose and Close methods for the SPWeb object and SPSite object function in the same way. The Dispose method calls the object's Close method. MS recommends calling the Dispose method, instead of Close, because SPWeb and SPSite objects implement the IDisposable interface, and standard .NET Framework garbage collection calls the Dispose method to free any resources associated with the object from memory.
You can automatically dispose of SharePoint objects that implement the IDisposable interface by using the Microsoft Visual C# using statement.

String str;
using(SPSite oSPsite = new SPSite(http://server/))
{
   using(SPWeb oSPWeb = oSPSite.OpenWeb())

    {
      str = oSPWeb.Title; 
      str = oSPWeb.Url;
     }
}

void OpenWebNoLeak()

 { 
String str;
using (SPSite siteCollection = new SPSite(http://moss/))
{
   using (SPWeb web = siteCollection.OpenWeb())
  {
     str = web.Title;
    str = web.Url;
  } // SPWeb object web.Dispose() automatically called.
} // SPSite object siteCollection.Dispose() automatically called.
}

Bad coding practices 
Ex1 
// Do not do this. Dispose() is automatically called on SPWeb.
using( SPWeb web = SPControl.GetContextWeb(HttpContext.Current)) { ... }

 Ex2 
using (SPWeb web = new SPSite(SPContext.Current.Web.Url).OpenWeb())
{
// ... New SPSite will be leaked.
} // SPWeb object web.Dispose() automatically called.
Ex3 
void SPControlBADPractice()
{
   SPSite siteCollection = SPControl.GetContextSite(Context);
   siteCollection.Dispose(); // DO NOT DO THIS
   SPWeb web = SPControl.GetContextWeb(Context);
   web.Dispose(); // DO NOT DO THIS.
}

 Good practices 
Thumb rule
If you create the object with a new operator, ensure that the creating application disposes of it.
Ex1 
void CombiningCallsBestPractice()
{

  using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Url))
 {
   using (SPWeb web = siteCollection.OpenWeb()) 
   {
    //Perform operations on site.
   } // SPWeb object web.Dispose() automatically called.
} // SPSite object siteCollection.Dispose() automatically called.
}

If we are not performing any operations on the SPSite object, we could write this more succinctly, as in the following code example. 
void CombiningCallsBestPractice()
{
 using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Url)) 
   using (SPWeb web = siteCollection.OpenWeb())
    {
      //Perform operations on site.
    } // SPWeb object web.Dispose() automatically called; SPSite object
      // siteCollection.Dispose() automatically called.
}

Ex2 
Try and finally blocks or a using statement would be required to avoid potential leaks when you create a disposable object within a foreach block,
public static void SPSiteCollectionForEachBestPractice()
{
string sUrl = http://rajtestsite/
using (SPSite siteCollectionOuter = new SPSite(sUrl))
   SPWebApplication webApp = siteCollectionOuter.WebApplication;
   SPSiteCollection siteCollections = webApp.Sites;
   SPSite siteCollectionInner = null;
   foreach (siteCollectionInner in siteCollections)
   {
     try //Should be first statement after foreach.
     { 
        Console.WriteLine(siteCollectionInner.Url);
         //Exception occurs here.
      }
      finally
     {
        if(siteCollectionInner != null)
        siteCollectionInner.Dispose();
     }
  }
}
} // SPSite object siteCollectionOuter.Dispose() automatically called.
}
Ex 3
void SPControlBestPractice()
{
  SPSite siteCollection = SPControl.GetContextSite(Context);
  SPWeb web = SPControl.GetContextWeb(Context);
// Do NOT call Dispose().
}
Ex4 
void SPSiteCollectionAddNoLeak()
{
   SPWebApplication webApp = new SPSite("http://moss").WebApplication;
   SPSiteCollection siteCollections = webApp.Sites;
   using (SPSite siteCollection = siteCollections.Add("sites/myNewSiteCollection", "DOMAIN\\User",
   rajan@ms.com))
   {
    } // SPSite object siteCollection.Dispose() automatically called.
}

Same for webcollection.Add methods too.
Ex4
 SPSite.RootWeb Property & SPWeb.ParentWeb Property

It is no longer advisable to call the Dispose method on the SPSite.RootWeb property whenever any of these properties are used.
 public void RootWebBestPractice() 
{// New SPSite.
using (SPSite siteCollection = new SPSite(http://moss/))
{
   SPWeb rootWeb1 = siteCollection.RootWeb;
// No explicit rootWeb1 dispose required.
} // siteCollection automatically disposed by implementing using().
// rootWeb1 will be Disposed by SPSite.
// SPContext and SPControl
SPWeb rootWeb2 = SPContext.Current.Site.RootWeb;
// Also would apply to SPControl.GetContextSite(Context); 
// No explicit rootWeb2 dispose required because it's obtained from SPContext.Current.Site.
}
It is no longer advisable to call the Dispose method on SPWeb.ParentWeb property whenever any of these properties are used.
using (SPSite site = new SPSite(http://localhost/))
{
using (SPWeb web = site.OpenWeb())
{
   SPList list = web.Lists["Announcements"]; 
   SPWeb parentWeb = list.ParentWeb; //No explicit dispose required.
}
}
Ex 5
SPWeb.Webs Property
The SPWeb.Webs property returns an SPWebCollection object. The SPWeb objects in this collection must be disposed.
void WebsNoLeak()
{
using (SPSite siteCollection = new SPSite(http://moss/))
{

   using (SPWeb outerWeb = siteCollection.OpenWeb()) 
    {
       foreach (SPWeb innerWeb in outerWeb.Webs)


        {   try //Should be first statement after foreach. 
              {   // ...}
            finally 
              {
                 if(innerWeb != null)
                 innerWeb.Dispose();
               }
          }

 } // SPWeb object outerWeb.Dispose() automatically called. 
} // SPSite object siteCollection.Dispose() automatically called.
}

 Cross Method Dispose Patterns

 The following example demonstrates the common practice of holding onto the SPSite and SPWeb objects across methods in a class. Sometimes this design pattern is required, but ensure that you do not overlook the appropriate time to call Dispose when you are finished with the cross method calls. The following code example shows a pattern where SPSite and SPWeb leak when the class goes out of scope.

public class CrossMethodLeak
{
private SPSite _siteCollection = null;
private SPWeb _web = null;
public void MethodA()
{
   _siteCollection = new SPSite(http://moss/);
   _web = _siteCollection.OpenWeb();
}

  public void MethodB() 
{
   if (_web != null)
   {
    string title = _web.Title;
   }
}

public void MethodC()

 {
   if (_web != null)
    {

      string name = _web.Name; 
    }
 }
}

Conclusion 
Because many SharePoint objects implement the IDisposable interface, you must take care when using these objects to avoid retaining them in memory. You can read the completed article here

SharePoint Dispose Checker Tool

SPDisposeCheck is a tool that helps developers and administrators check custom SharePoint solutions that use the SharePoint Object Model helping measure against known Microsoft dispose best practices. This tool may not show all memory leaks in your code and may produce false positives which need further review by subject matter experts.

12/13/2010 update: SPDisposeCheck v14.0.4762.1000
SPDisposeCheck tool can be downloaded
http://archive.msdn.microsoft.com/SPDisposeCheck