Problem with the simple module sample - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Problem with the simple module sample

  • Problem with the simple module sample
  • Hello,

    I successfully registered the JobApplication sample module to a sitefinity website.
    When i test it, though, I get an unhandled exception.
    Tracking and removing a try/catch, Imanaged to find the line in which the exception happens on the Job.cs file in the  : 
    sf.Document().CreateNew().Do(item =>
                            item.Parent = sf.DocumentLibraries().Where(l => l.Title == "JobApplications").Get().FirstOrDefault();
                            item.Title = title; item.UrlName = title + "_Application";
                            item.SetValue("FirstName", firstName);
                            item.SetValue("LastName", lastName);
                            item.SetValue("Phone", phone);
                            item.SetValue("HowDidYouHear", howDidYouHear);
                        ).CheckOut().UploadContent(applicationFile.InputStream, applicationFile.GetExtension()).CheckInAndPublish();

    The exception is on an null/unreferenced object. here is the cal stack i get :

    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Sitefinity.Libraries.Model.MediaContent.PreStore() +72
       OpenAccessRuntime.DataObjects.PCStateMan.doJDOPreStore(LifecycleListenerManager[] listeners) +212
       OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.callPreStore() +89
       OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.prepareForStore(Boolean commit) +48
       OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.flush() +75

    [OpenAccessException: Object reference not set to an instance of an object.]
       Telerik.Sitefinity.Data.TransactionManager.CommitTransaction(String transactionName) +592
       Telerik.Sitefinity.Fluent.FluentSitefinity.Dispose() +46
       Jobs.JobsModule.UploadApplication(String firstName, String lastName, String phone, String howDidYouHear, UploadedFile applicationFile) in C:\Users\administrator\Documents\Visual Studio 2010\Projects\Jobs\JobsModule.cs:193
       Jobs.PublicControls.JobApplicationUpload.JobApplicationUpload_Click(Object sender, EventArgs e) in C:\Users\administrator\Documents\Visual Studio 2010\Projects\Jobs\PublicControls\JobApplicationUpload.cs:157
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

    I don't think I've any non-instanced object, and my code is for now a copy paste of the sample "JobApplication" module project.

    Am I missing anything?
  • I have an extra information.

    Apparently, the "item.Parent" property is null.
    I believe it means my code can't find a "JobApplications" library.

    Is there a way to check in the code that this library exists? (It's supposed to be created at the module's registration).
    If not, how can I ensure its creation?

    Thank you.
  • I finally found out my problem came from a library with the URL "JobApplications" already existed, preventing the creation of a library with the same URL.
    I then created (in the code) a library with the URL "JobApplication2" to test my theory. It worked fine, and the module works now as intended.

    That leads me to the following question : How to properly delete a Library? I tried through the code with the line :

    sflib.DocumentLibraries().Where(l => l.UrlName == "JobApplications").Delete();

    but it doesn't seem to delete it.

    Is there a way to delete is through the interface? And what is the proper way to delete it through the code?

    Thank you,
  • Hi Lamari,

    You can delete the Library from the API if you retrieve it with the Fluent API code by its Name property such as this:

    App.WorkWith().DocumentLibraries().Where(a => a.Title == "MyLibrary").Delete().SaveChanges();

    Furthermore you can also delete it from the User interface if you navigate to the corresponding library on the right side menu of Documents & Files, open the library and click Delete from the Library actions menu such as shown below:

    Please let me know if you need further assistance.

    Best wishes,
    Hristo Borisov
    the Telerik team

    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!