TypeInitializer exception with Libraries.GetManager()
Hi,
I have the following code in a console application to work with Sitefinity 4.0 RC:
LibrariesManager libManager = LibrariesManager.GetManager();
When I step through the above line of code, I get the exception below:
"The type initializer for 'Telerik.Sitefinity.Modules.Libraries.LibrariesManager' threw an exception."
In particular, the InnerException is:
"Value cannot be null.\r\nParameter name: path1"
Am I doing something wrong or is this a Sitefinity bug? I have not posted the remaining code as this line of code doesn't use other fields I have in my class.
Thanks
Hello G S S,
Use a web service call from the console application. The our API is supposed to work in web environment, since you are trying to use it for desktop.
Regards,
Ivan Dimitrov
the Telerik team
Hi,
What do you mean by console application? The Sitefinity UI?
Also, I am supposed to save the content through the Content object, so how do I do this then?
Is it not possible to see a code sample of the process to upload content in an automated fashion? I've been trying for ages to upload content but with no help/examples!
Hello G S S,
"I have the following code in a console application .. "
en.wikipedia.org/.../Console_application
You can take a look at our SDK, Jobs module where you will find a sample that shows how to create /upload document item.
You can use LibrariesManager.Upload(MediaContent content, Stream source, string extension) method.
Regards,
Ivan Dimitrov
the Telerik team
Hi,
Sorry, I forgot that I mentioned console. Anyway, I looked at the job module and found this code:
using (var sf = App.Prepare().SetTransactionName("UploadTransaction").WorkWith()) sf.Document().CreateNew().Do(item => item.Parent = sf.DocumentLibraries().Where(l => l.Title == "Default Library").Get().FirstOrDefault(); item.Title = "test"; item.SetValue("FirstName", "s"); item.SetValue("LastName", "S"); item.SetValue("Phone", "s"); item.SetValue("HowDidYouHear", "s"); ).CheckOut().UploadContent(GetStream(new FileInfo(@"C:\Test\test.rar")), ".rar").CheckInAndPublish();
Is there a fix for the above?
Hi G S S,
You do not have a reference to the LibrariesManager in the console application.
You can also use our wcf services to make a requests to Sitefinity
www.sitefinity.com/.../deep-dive-client-side-programming-restful-wcf-services-in-sitefinity.html
You can use WebRequest or Sys.Net.WebRequest();
Best wishes,
Ivan Dimitrov
the Telerik team
Hi,
I will try WCF to do what I need, or add the missing reference to my console project (I'll see what that needs).
Can you provide a C# sample of how the code would look to upload a document via WCF to Sitefinity?
Thanks
Hi G S S,
1. You need to authenticate yourself, because you cannot use our service with an anonymous account
2. You can check the service methods typing
Sitefinity/Services/Content/ImageService.svc/help
after the website host.
3. You would not be able to call the service using ClientManager or jQuery ajax. You need to use WebRequest from console application or some control.
All the best,
Ivan Dimitrov
the Telerik team
Hi,
I will use the Credentials class to authenticate.
I will try webrequest.
I will save content and get the GUID and use that in the querystring.
BTW, I also saw this in the jobs starter site:
App.WorkWith().Pages().Where(p => p.Id == pageId).Count(out count);
if (count == 0)
var templateId = SampleUtilities.RegisterDefaultSamplesThemeAndTemplate();
App.WorkWith().Page()
.CreateNewStandardPage(
.CreateNewStandardPage
PageLocation.Frontend, pageId, pageDataId)
.Do(p =>
.Dop=>
p.Title = pageName;
p.Name = pageName;
p.UrlName = pageName;
p.ShowInNavigation =
p.Title=pageNamep.Name=pageNamep.UrlName=pageNamep.ShowInNavigation=
true;
p.DateCreated =
DateTime.UtcNow;
p.LastModified =
p.LastModified=
DateTime.UtcNow;
p.Page.HtmlTitle = pageName;
p.Page.Title = pageName;
p.Description =
p.Page.HtmlTitle=pageNamep.Page.Title=pageNamep.Description=
"This is a home page created for a specific Sitefinity Sample.";
)
.CheckOut()
.SetTemplateTo(templateId)
.Control()
.CreateNew(widget,
"Content")
.SaveChanges()
.Done()
.Publish()
.SaveChanges();
Hi G S S,
If you are not authenticated you cannot use our WCF services. For each content items we have difference facade that you can use. You can check this by typing App.WorkWith() in VS.
Creating and editing objects also requires that you should authenticate a valid user with the proper permissions. Another option is using RPC - create a standard web service in Sitefinity 4.x website with the api methods where you use the managers or fluent API and access this service from your other application.
All the best,
Ivan Dimitrov
the Telerik team
Maybe I'll try the RPC approach. The service in IIS will be RPC but I will invoke this from outside, correct?
RE authentication - is this done programatically via the Sitefinity API?
Hello G S S,
If you use RPC you don't need to authenticate the user, since the code will execute inside Sitefinity application and you can call Provider.SuppressSecurityChecks = true for the provider you are going to use. After you complete the operation you use set the security checks back to false which is the default value.
Kind regards,
Ivan Dimitrov
the Telerik team