0

I am studying custom document template.I have created a ListInstance of type Document Library and also created Module using Visual Studio 2010.Then I had created a Application page.In its page load i have pasted the following code

  using (SPSite site = new SPSite("http://pc81:2000/"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPDocumentLibrary lib = (SPDocumentLibrary)web.Lists["YbbestCustomDocLib"];
                string urlStr = @"Lists/YbbestCustomDocLib/Forms/Sample.txt";
                lib.DocumentTemplateUrl = urlStr;
                lib.Update();

            }
        }

But when i load this application page, at the point of type casting SPList to SPDocumentLibrary i am getting an error "Unable to cast object of type 'Microsoft.SharePoint.SPList' to type 'Microsoft.SharePoint.SPDocumentLibrary".Please help me to resolve this

1

Can you try:

SPList list = web.Lists["YbbestCustomDocLib"];
SPDocumentLibrary lib = (SPDocumentLibrary) list;

or

SPList list = web.Lists["YbbestCustomDocLib"];
SPDocumentLibrary lib = list as SPDocumentLibrary;
|improve this answer|||||
  • Working fine now – anish Oct 11 '13 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.