Archive for the ‘Microsoft / CRM / SharePoint / SSRS’ Category

Automatic migration was not applied because it would result in data loss.

I’ve just started using EntityFramework.Migrations and came accross this error:

No pending explicit migrations.
Applying automatic migration: 201205101614472_AutomaticMigration.

Automatic migration was not applied because it would result in data loss.


It’s because my migrations would’ve nuked some of my data. I’m okay with that though, you just need to throw on the -Force tag to get it to complete the migration:

Update-Database -Verbose -Force

Using Sharepoint 2010 SOAP/Web Client – C#

I’ve been meaning to post this for a while since I had some annoying issues with CAML and Sharepoint 2010. Here’s the structure I’m using:

I’ve had to do quite a few things with the Sharepoint 2010 web services and web client object. I figured I should post some solutions as quite a few of these are undocumented. My goal was not to have to import the SP Library and just use the web services along with the basic GET PUT methods of the WebClient.

Create a Folder with SharePoint 2010 via SOAP Web Services – UpdateListItems
http://www.ryanonrails.com/2011/10/11/create-a-folder-with-sharepoint-2010-via-soap-web-services-updatelistitems/

Upload a document to Sharepoint 2010 via WebClient
http://www.ryanonrails.com/2011/09/17/upload-a-document-to-sharepoint-2010-via-webclient/

Retrieve document ID from SharePoint 2010 via SOAP Web Services – GetListItems
http://www.ryanonrails.com/2011/08/30/retrieve-document-id-from-sharepoint-2010-via-soap-web-services-getlistitems/

Update Custom Columns from SharePoint 2010 via SOAP Web Services – UpdateListItems
http://www.ryanonrails.com/2011/08/30/update-custom-columns-from-sharepoint-2010-via-soap-web-services-updatelistitems/

Check in a file into SharePoint 2010 via SOAP Web Services – CheckInFile
http://www.ryanonrails.com/2011/08/30/check-in-a-file-into-sharepoint-2010-via-soap-web-services-%E2%80%93-checkinfile/

Delete document from SharePoint 2010 via SOAP Web Services – UpdateListItems
http://www.ryanonrails.com/2011/08/30/delete-document-from-sharepoint-2010-via-soap-web-services-updatelistitems/

Download a document from Sharepoint 2010 via WebClient
http://www.ryanonrails.com/2011/10/11/download-a-document-from-sharepoint-2010-via-webclient/

Download a document from Sharepoint 2010 via WebClient

Here’s how I use the WebClient object to download a pdf from Sharepoint 2010:

string uri = "wwww.google.ca";
string filepath = "waffles.pdf";
 
WebClient wc = new WebClient();
wc.Credentials = loginCredentials;
byte[] generatedPdf = wc.DownloadData(uri + "/" + filePath);

Create a Folder with SharePoint 2010 via SOAP Web Services – UpdateListItems

Here’s a call to SharePoint 2010 for creating a folder. Note the RootFolder.

// Build the CAML Query
System.Text.StringBuilder oSb = new System.Text.StringBuilder();
oSb.Append("     <Batch OnError=\"Continue\" RootFolder=\"\" >");
oSb.Append("         <Method ID=\"1\" Cmd=\"New\">");
oSb.Append("             <Field Name=\"ID\">New</Field> ");
oSb.Append("             <Field Name=\"FSObjType\">1</Field> "); // 1 = folder, 0 = document
oSb.Append("             <Field Name=\"BaseName\">" + folderName + "</Field> ");
oSb.Append("        </Method>");
oSb.Append("    </Batch>");
 
string sResult = oSb.ToString();
XmlDocument CAMLqueryXML = new XmlDocument();
CAMLqueryXML.LoadXml(sResult);
 
// Execute UpdateListItems
System.Xml.XmlNode result = lists.UpdateListItems(SPLibraryName, CAMLqueryXML);

Upload a document to Sharepoint 2010 via WebClient

Here’s some code on how to upload a document into Sharepoint 2010. This works accross domains:

WebClient wc = new WebClient();
wc.Credentials = loginCredentials;
wc.UploadData(destinationUrl, "PUT", fileData);

A big FYI. The Copy.asmx web service will NOT work across domains. Using the above method will work for all occasions (of course the only issue is that you need to update the columns in a separate call.

Return top