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 :
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();
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