Registering an E-Learning Package using the API

Topics: Developer Forum
Jul 27, 2009 at 5:44 PM

Hi everyone.

I'm trying to build an assignment from scratch.

I'm building code, so that it can upload the package and create the assignment, all through the API.

I'm able to upload the package to a document library. But when it comes to build the assignment, it gets tricky.

I believe i have to register the package. However, i can't seem to understand the SlkStore.RegisterPackage() method. What is the location in this method?

This is how i was trying to do it:

string docPath = "c:\\saf\\"; //physical location of the file
                            fileStream = File.OpenRead(docPath + fileName);
                            fileContent = new byte[Convert.ToInt32(fileStream.Length)];
                            fileStream.Read(fileContent, 0, Convert.ToInt32(fileStream.Length));
                            SPFile spfile = spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + fileName, fileContent, true);
                            string packageUrl = "http://mySite/Shared%20Documents/" + fileName;
                            AssignmentItemIdentifier assignmentId;

                            SlkStore slkStore = SlkStore.GetStore(myWeb);
                            PackageItemIdentifier packageItemId;
                            LearningStoreXml warnings;
                            string location = new SharePointFileLocation(myWeb, spfile.UniqueId, spfile.UIVersion).ToString();

However, i get the following error:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.LearningComponents.SharePoint.SharePointFileLocation.GetTimeStamp(Guid siteId, Guid webId, Guid fileId, Int32 versionId)
   at Microsoft.LearningComponents.SharePoint.SharePointFileLocation..ctor(SPWeb web, Guid fileId, Int32 versionId)


Can someone help me on this?

Thanks in advance,

Rafael Canelas

Aug 4, 2009 at 1:15 AM

Hi Rafael,

Where is this code running? Is it a console application. Just looked at the source code for SharePointFileLocation.GetTimeStamp and it used SPContext.Current so unless it's running in a SharePoint page it's not going to work.

Looks like a bad design decision to me. Try using a different constructor

public SharePointFileLocation(Guid siteId, Guid webId, Guid fileId, int versionId, DateTime timestamp)


SLK Co-ordinator

Aug 4, 2009 at 12:25 PM

Hi there.

Yup, i'm running it in a console app.

Yes, i checked the source code too, and i got to the same conclusion as you. I've already tried the SharePointFileLocation(Guid siteId, Guid webId, Guid fileId, int versionId, DateTime timestamp) constructor, and it works, but then, on the next steps, the same thing happens beacause the SPContext doesn't exist. I haven't been able to complete the registry of the package.

Shoul this be a question launched in the Issues forum?



Rafael Canelas

Aug 5, 2009 at 5:38 PM

Any resolution to this?  I'm running into similiar problems when registering an e-learning package through the API.

Aug 6, 2009 at 8:50 AM

No luck.

The API is written in a way that only works when there is a HTTP context. If one, does not exist, like when you try it in a console app, i don't think that you'll be able to register the package through the API.

Like Richard said in the reply above, it's a design flaw.


Rafael Canelas

Aug 6, 2009 at 3:37 PM

This particular part of the API must have changed from the previous version of the SLK because it worked fine before I upgraded to 1.3.1.  Have you looked at the source to see how complex the changes would be?