Adding attributes in LINQ using element.add - attributes

I have to write information from textboxes to XML file on click event.
My sample code would look lik this.
XDocument xmlDoc = XDocument.Load(fileName);
xmlDoc.Element("Mediaplans").Add(new XElement("MediaPlan", new XElement("Media",TxtMedia.Text),
new XElement("Adtype", TxtAdtype.Text), new XElement("EmailId",TxtEmailId.Text)));
xmlDoc.Save(fileName).
What I want to know is how do we add attributes to elements with the above method?
I am new to this field. any help appreciated.
Thanks,
Kruthika

You can call Add and pass an XAttribute too.

You can just use add new XAttribute like you have done with XElement.
Have a look at this link for an example
I believe that you should be able to do something like
XDocument xmlDoc = XDocument.Load(fileName);
xmlDoc.Element("Mediaplans").Add(new XAttribute("File name", fileName),new XElement("MediaPlan", new XElement("Media",TxtMedia.Text), new XElement("Adtype", TxtAdtype.Text), new XElement("EmailId",TxtEmailId.Text));
xmlDoc.Save(fileName).
Sorry dont have access to VS at the moment so I cant verify the code.

Related

How to find all documents in couchDB using ektrop library

I have gone through all the blogs available for the ektrop library and also the source code of the library.I have found that get(class obj,String id) function is available but If I use this function then only one document will be returned according to the id given.So I want to read all the changed documents present in the bucket.How Can I achieve this.Thanks in advance any help would be appreciable.
You are probably looking for the _all_docs endpoint.
ViewQuery q = new ViewQuery().allDocs().includeDocs(true);
List<Sofa> bulkLoaded = db.queryView(q, Sofa.class);
You can find more detailed information in the api
Hello all I have got the answer the question asked by me above.Here is the steps by which you can get the all documents or simply the result of _changes API is used.
Integrate the Ektorp library into your project.
Use the follwing code to get the all document.
HttpClient httpClient = new StdHttpClient.Builder()
.url("http://localhost:5984/")
.build();
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
CouchDbConnector db = new StdCouchDbConnector("my_database", dbInstance);
ChangesCommand.Builder builder = new ChangesCommand.Builder();
ChangesCommand changesCommand =builder.build() ;
List<DocumentChange> documentChangeList=db.changes(changesCommand);
for(int i=0;i<documentChangeList.size()-1;i++) {
System.out.println(documentChangeList.get(i).getId());
}

DocumentDB Replace not Working

I recently realized that DocumentDB supports stand alone update operations via ReplaceDocumentAsync.
I've replaced the Upsert operation below with the Replace operation.
var result = _client
.UpsertDocumentAsync(_collectionUri, docObject)
.Result;
So this is now:
var result = _client
.ReplaceDocumentAsnyc(_collectionUri, docObject)
.Result;
However, now I get the exception:
Microsoft.Azure.Documents.BadRequestException : ResourceType Document is unexpected.
ActivityId: b1b2fd71-3029-4d0d-bd5d-87d8d0a2fc95
No idea why, upsert and replace are of the same vein and the object is the same that worked for upsert, so I would expect it to work without problems.
All help appreciated.
Thanks
Update: Have tried to implement this using the SelfLink approach, and it works for Replace, but selflink does not work with Upsert. The behavior is quite confusing. I don't like that I have to build a self link in code using string concatenation.
I'm afraid that building the selflink with string concatenation is your only option here because ReplaceDocument(...) requires a link to the document. You show a link to the collection in your example. It won't suck the id out and find the document as you might wish.
The NPM module, documentdb-utils, has library functions for building these links but it's just using string concatenation. I have seen an equivalent library for .NET but I can't remember where. Maybe it was in an Azure example or even in the SDK now.
You can build a document link for a replace using the UriFactory helper class:
var result = _client
.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, docObject.Id), docObject)
.Result;
Unfortunately it's not very intuitive, as Larry has already pointed out, but a replace expects a document to already be there, while an upsert is what it says on the tin. Two different use-cases, I would say.
In order to update a document, you need to provide the Collection Uri. If you provide the Document Uri it returns the following:
ResourceType Document is unexpected.
Maybe the _collectionUri is a Document Uri, the assignment should look like this:
_collectionUri = UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName);

Getting PDF_VALIDATION_FAILED exception when trying to create envelopne in DocuSign sample recipe code

I am trying to run the code available on GitHub.
Issue is when I am trying to create an envelope I am getting an exception saying "PDF_VALIDATION_FAILED".
Can anyone help me out with this issue?
Really you should be creating a new issue to log the new error you are getting, or modify your original post. In any case the issue is most likely due to the file extension, the default is pdf so if you want to send a different format document you can do the following:
// Add a document to the envelope
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = Path.GetFileName("/PATH/TO/DOC/TEST.DOCX");
doc.DocumentId = "1";
doc.FileExtension = "docx";
I managed to get a fix for this one. Apparently the file I was uploading was a corrupt file. However, not I am getting a different error 'UNABLE_TO_LOAD_DOCUMENT' when I try to upload a file in any format other than pdf.
Can anyone help me with this query? Also, what all file formats does DocuSign support?
Also, one of the previous libraries 'DocuSign.Integrations.Client' seem to work fine with word document uploads. Should they be used instead of 'DocuSign.eSign.Api', 'DocuSign.eSign.Client' and 'DocuSign.eSign.Model'?
This is in response to the second error you mentioned:
I think you are missing assigning the FileExtension to the required format
something like : doc.FileExtension = "docx"
Once you do that, you will get rid of UNABLE_TO_LOAD_DOCUMENT error and the document can be sent successfully.

How to remove Custom Properties from a SoapUI TestCase using Groovy?

I have created some list of properties under the TestCase. For example look at the following screenshot.
I tried to remove Testcase_Property property through the following groovy script teststep:
testRunner.testCase.testSuite.removeProperty( "Testcase_Property" );
when I reload the project, the Testcase_Property property is still exist in the Custom Properties tab when I click on the Test case name.
Anyone suggest me what the correct script to remove the custom properties in SoapUI.
Thanks
Karunagara Pandi
you can also use the following:
data = context.testCase.getTestStepByName("Test Case Name");
String[] propToRemove = new String[data.getPropertyCount()];
propToRemove = data.getPropertyNames();
for ( int i = 0 ; i < propToRemove.size(); i++ ){
data.removeProperty( propToRemove[i] );
}
Hope this helps.
Now you can remove more than one prop.
Finally I got the answers for removing Project, Testsuite and Testcase custom properties. Here are the scripts.
testRunner.testCase.testSuite.project.removeProperty( "Project_Level_Property" );
testRunner.testCase.testSuite.removeProperty( "Testsuite_Property" );
testRunner.testCase.removeProperty( "Testcase_Property" );
If any other way is there, please let me know friends.
Manual solution: use "Save Properties" and "Load Properties" from SoapUI
export the properties to a text file, e.g. customprop.txt
edit the file and delete the unwanted properties
import the file back into your soapUI project
in the "load properties" dialog check the option to "delete remaining"
Then the existing properties will be cleared out and replaced with your customprop.txt
Just for completeness:
Another quick but dirty and dangerous way is to modify the soapui-project.xml and remove the property nodes with a text editor.
Be aware that you can break your whole project if you do something wrong!
You should create a copy of your soapui-project.xml and do the following steps:
Set the values of the Properties you want to delete to deleteMe
Search for the string deleteMe in your soapui-project.xml
Delete the properties:
<con:property><con:name>name</con:name><con:value>deleteMe</con:value></con:property>

How to create project issue in Project Workspace programmatically?

I would like to be able to create project issue automatically. The aim is to create new issue based on received email.
I looked at ProjectWSSInfoDataSet, which is supposed to have reference to issue list (according to "PSI Methods and DataSets for Project Workspaces" at http://msdn.microsoft.com/en-us/library/aa495198(office.12).aspx). Indeed, ProjectWSSInfoDataSet XML schema contains PROJECT_ISSUES_URL field, but if it is just the url then it is not much usefull for me.
Has anyone did something similar? (Or possibly with project risks or deliverables.)
I think have to do it with the SharePoint Webservices. Find the list in the specified web and update it.
I recommend the SharePoint 2010 Client Object Model to do this:
//Use SP2010 Client Object Model to update the list
ClientContext SPContext = new ClientContext(wssUrl);
//Get list by name
string listname = "issues";
var query = SPContext.LoadQuery(SPContext.Web.Lists.Where(l => l.Title == listname));
SPContext.ExecuteQuery();
List myIssueList = query.FirstOrDefault();
//Add an item
ListItemCreationInformation nItem = new ListItemCreationInformation();
nItem.LeafName = "Blubb..";
myIssueList.AddItem(nItem);
SPContext.ExecuteQuery();
If you wan't to get the Workspace Url via the Project Id, you can do this by WSSInterop Webservice of the Project Server:
//Use WssInterop Webservice to get the Workspace URL
WssInteropSoapClient wssinteropSvc = new WssInteropSoapClient();
Guid prjGuid = new Guid("30937680-39FA-4685-A087-90C73376B2BE");
ProjectWSSInfoDataSet wssData = wssinteropSvc.ReadWssData(prjGuid);
string wssUrl = wssData.ProjWssInfo[0].PROJECT_WORKSPACE_URL;
I don't know if the code will compile, but it should work like this.
Regards Florian

Resources