I am trying to programatically insert a discussion post into a Sharepoint discussion board list using the client object model in C#. I am using the following code:
var discussionList = sharepointContext.Web.Lists.GetByTitle("Discussion");
var discussionItem = Utility.CreateNewDiscussion(sharepointContext, discussionList, "Test");
discussionItem["Body" ] = "Hello world!"
discussionItem["Author" ] = 22;
discussionItem["Editor" ] = 22;
sharepointContext.Load(discussionItem);
discussionItem.Update();
sharepointContext.ExecuteQuery();
However, whenever I run it, I get this exception
Microsoft.SharePoint.Client.ServerException was unhandled
Message=Field or property "Body" does not exist.
Source=Microsoft.SharePoint.Client.Runtime
ServerErrorCode=-1"
Does anyone know what I'm doing wrong?
The reason the code in the question didn't work is because you called Update() after calling SPContext.Load(). If you call Update() first, you'll be fine.
Related
I am trying to run code from the Autodesk help
http://help.autodesk.com/view/RVT/2014/ENU/?guid=GUID-B6FB80F2-7A17-4242-9E95-D6056090E85B
private void CreateViewFilter(Autodesk.Revit.DB.Document doc, View view)
{
List<ElementId> categories = new List<ElementId>();
categories.Add(new ElementId(BuiltInCategory.OST_Walls));
ParameterFilterElement parameterFilterElement =
ParameterFilterElement.Create(doc, "Comments = foo", categories);
FilteredElementCollector parameterCollector = new FilteredElementCollector(doc);
Parameter parameter = parameterCollector.OfClass(typeof(Wall)).FirstElement().get_Parameter("Comments");
List<FilterRule> filterRules = new List<FilterRule>();
filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(parameter.Id, "foo", true));
parameterFilterElement.SetRules(filterRules);
OverrideGraphicSettings filterSettings = new OverrideGraphicSettings();
// outline walls in red
filterSettings.SetProjectionLineColor(new Color(255, 0, 0));
view.SetFilterOverrides(parameterFilterElement.Id, filterSettings);
}
When I open a view and run the code more than once, I get the following error
Revit encounterd a argumentException. The given value for name is already in use as a filter element name parmeter name: name at ParameterFilterElement parameterFilterElement = ParameterFilterElement.Create(doc, "Comments= foo", categories). I can't see where this happened in the code.(OBS I change the get_parameter to lookupparameter in the original code above because the first is deprecated)
According to the docs, the second parameter to the Create method is name. The error message states that you are already using the name "Comments = Foo". So I think your best bet is to dynamically generate the name or provide a way for a user to specify the name.
After a little bit thinking I get it. Actually I should do that from the beginging. Anyway the prgram create filter and It is now in the view so when I run the command again there is already one. Thank you.
I am trying to post a tweet with TweetSharp library but a StackOverflowException is thrown. I couldn't solve this problem. What should I do? The error occurs in this line:
servis.SendTweet(new SendTweetOptions { Status = textBox1.Text });
Break it down and step through in the debugger (put a break-point on the string status = ... line):
// if you don't get this far, the problem is elsewhere
// if it fails here, the problem is accessing the textbox value
string status = textBox1.Text;
// if it fails here, the problem is inside the tweetsharp library,
// and should be referred to the library authors, but indicating which
// step fails (constructor vs Status property vs Send method)
var msg = new SendTweetOptions();
msg.Status = status;
servis.SendTweet(msg);
I'm trying to query a view using TouchDB in C#. I used the binding between TouchDB and MonoTouch available here : https://github.com/mono/monotouch-bindings/tree/master/Couchbase
When the emit delegate method is called, I get a "System.Runtime.InteropServices.MarshalDirectiveException" saying "The type MonoTouch.Foundation.NSObject which is passed to unmanaged code must have a StructLayout attribute."
I found this bug report here : https://bugzilla.xamarin.com/show_bug.cgi?id=4781 that is similar to my problem but there isn't any updates since July 27, 2012.
Here's my test code :
CouchTouchDBServer server = new CouchTouchDBServer ();
CouchDatabase database = server.GetDatabase ("grocery-sync");
database.TracksChanges = true;
// Create a test view
design = database.DesignDocumentWithName ("grocery");
design.DefineView ("testView", (doc,emit) => {
emit (doc, doc); // Crashes here
}, "1.0");
// Query the view
CouchQuery query = design.CereateQuery("testView");
RestOperation op = query.Start();
string response = op.ResponseBody.AsString;
Console.WriteLine(response);
Has anyone successfully queried a view on TouchDB with MonoTouch? Thanks for your help
It seems to be a bug of Xamarin
Im trying to update "StatE Code" (Active|Inactive) to Active through the CRM web service on a product in the database.
...
crmProduct.statecode = new ProductStateInfo() { Value = ProductState.Active };
//crmProduct.statuscode = new Status() { Value = 1 };
crmProduct.name = "...";
service.Update(crmProduct);
It seem to work okay, I get no errors and the name changes, but its still Inactive!
When trying to set "StatUS Code" as well to Active, I get an error saying I cant set status to Active when state is Inactive... but Im setting both to Active at the same time... hmmmm.. dont now whats wrong here...
Any clues?
Setting the state code in an entity has no effect when you save it. You must use an appropriate SetState request. As Matt said, for dynamic entities this is the SetStateDynamicEntityRequest. In your case I am assuming you are using a "product" object, so you need to use the SetStateProductRequest class.
var request = new SetStateProductRequest()
{
EntityId = [GUID of product],
ProductState = ProductState.Active,
ProductStatus = -1
}
var response = (SetStateProductResponse)crmService.Execute(request);
Check out this link: http://msdn.microsoft.com/en-us/library/bb958061.aspx
The -1 for the ProductStatus tells CRM to use to appropriate default statuscode value for the statecode.
You have to use the SetStateDynamicEntityRequest to update the state of a record. You can update the statuscode using the regular update message, but only if the code you're updating to is in the same state that the record is currently in, as you've found.
I am attempting to load document files into a document library in SharePoint using the CopyIntoItems method of the SharePoint Copy web service.
The code below executes and returns 0 (success). Also, the CopyResult[] array returns 1 value with a "Success" result. However, I cannot find the document anywhere in the library.
I have two questions:
Can anyone see anything wrong with my code or suggest changes?
Can anyone suggest how I could debug this on the server side. I don't have a tremendous amount of experience with SharePoint. If I can track what is going on through logging or some other method on the server side it may help me figure out what is going on.
Code Sample:
string[] destinationUrls = { Uri.EscapeDataString("https://someaddress.com/Reports/Temp") };
SPCopyWebService.FieldInformation i1 = new SPCopyWebService.FieldInformation { DisplayName = "Name", InternalName = "Name", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Name" };
SPCopyWebService.FieldInformation i2 = new SPCopyWebService.FieldInformation { DisplayName = "Title", InternalName = "Title", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Title" };
SPCopyWebService.FieldInformation[] info = { i1, i2 };
SPCopyWebService.CopyResult[] result;
byte[] data = File.ReadAllBytes("C:\\SomePath\\Test1Data.txt");
uint ret = SPCopyNew.CopyIntoItems("", destinationUrls, info, data, out result);
Edit that got things working:
I got my code working by adding "http://null" to the SourceUrl field. Nat's answer below would probably work for that reason. Here is the line I changed to get it working.
// Change
uint ret = SPCopyNew.CopyIntoItems("http://null", destinationUrls, info, data, out result);
I think the issue may be in trying to set the "Name" property using the webservice. I have had some fail doing that.
Given the "Name" is the name of the document, you may have some success with
string targetDocName = "Test1Name.txt";
string destinationUrl = Uri.EscapeDataString("https://someaddress.com/Reports/Temp/" + targetDocName);
string[] destinationUrls = { destinationUrl };
SPCopyWebService.FieldInformation i1 = new SPCopyWebService.FieldInformation { DisplayName = "Title", InternalName = "Title", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Title" };
SPCopyWebService.FieldInformation[] info = { i1};
SPCopyWebService.CopyResult[] result;
byte[] data = File.ReadAllBytes("C:\\SomePath\\Test1Data.txt");
uint ret = SPCopyNew.CopyIntoItems(destinationUrl, destinationUrls, info, data, out result);
Note: I have used the "target" as the "source" property. Don't quite know why, but it does the trick.
I didn't understand very well what you're tying to do, but if you're trying to upload a file from a local directory into a sharepoint library, i would suggest you create a webclient and use uploadata:
Example (VB.NET):
dim webclient as Webclient
webClient.UploadData("http://srvasddress/library/filenameexample.doc", "PUT", filebytes)
Then you just have to check in the file using the lists web service, something like:
listService.CheckInFile("http://srvasddress/library/filenameexample.doc", "description", "1")
Hope it was of some help.
EDIT: Don't forget to set credentials for the web client, etc.
EDIT 2: Update metada fields using this:
listService.UpdateListItems("Name of the Library, batchquery)
You can find info on building batch query's in here: link
The sourceurl is used in Sharepoint. It is a link back to the "Source Document." When in your document library, hover over the item, to the right appears a down pointing triangle. Clicking on it, brings up a menu. Click on the "View Properties" Option. On this page you will see the following "This item is a copy of http://null ( Go To Source Item | Unlink )"
Because we are using the Copy function Sharepoint is keeping track of the "Source item" as part of the Document Management feature.