Update a OneNote page, using the developer API - c#

I tried to update a page in OneNote with the Microsoft reference :
http://msdn.microsoft.com/en-us/library/office/jj680118.aspx
Here's my problem. When i tried to update my page with the correct ID, it throwed me an error saying : Exception from HRESULT: 0x80042000.
Here is my code :
static void UpdatePageContent()
{
ApplicationClass onApplication = new ApplicationClass();
String strImportXML;
strImportXML = #"<?xml version="+"1.0"+" encoding="+"utf-16"+"?>" +
" <one:Page xmlns:one="+"http://schemas.microsoft.com/office/onenote/12/2004/onenote\""+"" +
"ID=\"{5BE09697-903A-45DD-88D4-8AD301A3D91F}{1}{B0}\">" +
" <one:PageSettings RTL=\"false\" color=\"automatic\">" +
" <one:PageSize>" +
" <one:Automatic/>" +
" </one:PageSize>" +
" <one:RuleLines visible=\"false\"/>" +
" </one:PageSettings>" +
" <one:Title style=\"font-family:Calibri;" +
" font-size:17.0pt\" lang=\"en-US\">" +
" <one:OE alignment=\"left\">" +
" <one:T>" +
" <![CDATA[My Sample Page]]>" +
" </one:T>" +
" </one:OE>" +
" </one:Title>" +
" <one:Outline >" +
" <one:Position x=\"120\" y=\"160\"/>" +
" <one:Size width=\"120\" height=\"15\"/>" +
" <one:OEChildren>" +
" <one:OE alignment=\"left\">" +
" <one:T>" +
" <![CDATA[Sample Text]]>" +
" </one:T>" +
" </one:OE>" +
" </one:OEChildren>" +
" </one:Outline>" +
" </one:Page>";
// Update page content
try
{
onApplication.UpdatePageContent(strImportXML, System.DateTime.MinValue);
}
catch (COMException e)
{
Console.WriteLine("Error Message : " + e.Message);
}
}
I really don't know how to solve this.

Your XML is not OneNote friendly.
Here's a list of error codes:
http://msdn.microsoft.com/en-us/library/office/jj680117.aspx
You can get rid of the first line, as #Sebastian has stated it's malformed anyway and my experience is that OneNote doesn't need it.
Also, remember that you don't need to send the entire page. You just need to send the page's objId and any updated objects. So one outline needs adding then this should also work:
"<one:Page xmlns:one=\"http://schemas.microsoft.com/office/onenote/12/2004/onenote\" +
"ID=\"{5BE09697-903A-45DD-88D4-8AD301A3D91F}{1}{B0}\">" +
" <one:Outline >" +
" <one:Position x=\"120\" y=\"160\"/>" +
" <one:Size width=\"120\" height=\"15\"/>" +
" <one:OEChildren>" +
" <one:OE alignment=\"left\">" +
" <one:T>" +
" <![CDATA[New Text]]>" +
" </one:T>" +
" </one:OE>" +
" </one:OEChildren>" +
" </one:Outline>";
Just this new outline will get added.
If you still get problems (it doesn't complain but the content doesn't update) then check the extra parameters for UpdatePageContent, certainly in the 2013 API one can send a last modified date to check and also there's a parameter to force a local over-write.

There are some issues in the strImportXML string, which causes the update to fail.
Adjust
#"<?xml version="+"1.0"+" encoding="+"utf-16"+"?>" to "<?xml version=\"" + "1.0" + "\" encoding=\"" + "utf-16" + "\"?>"
Add an empty space before the page ID attribute ( + " " + "ID...
instead of + "" + "ID)
Make sure that the page ID is found/ present in your onApplication
hierarchy
Make sure that you reference the COM library with the matching
namespace defined in the one:Page element (e.g. Office 2013/ 15.0
Object Library has another namespace)

Related

DocuSign RestApi - Error while uploading document - TAB_REFERS_TO_MISSING_DOCUMENT

I'm getting the following error when I try to apply a template (created in my web account) to the document I'm trying to upload.
"DocumentId specified in the tab element does not refer to a document in this envelope. Tab refers to DocumentId 41791752 which is not present."
Any help would be greatly appreciated. Thanks.
Here's the code I have:
string xmlBody = "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
"<emailSubject>DocuSign API - Signature Request"</emailSubject>" +
"<status>sent</status>" + // "sent" to send immediately, "created" to save as draft in your account
"<compositeTemplates>" +
"<compositeTemplate>" +
"<serverTemplates>" +
"<serverTemplate>" +
"<sequence>1</sequence>" +
"<templateId>" + templateID + "</templateId>" +
"</serverTemplate>" +
"</serverTemplates>" +
"<inlineTemplates>" +
"<inlineTemplate>" +
"<sequence>2</sequence>" +
"<recipients>" +
"<signers>" +
"<signer>" +
"<recipientId>1</recipientId>" +
"<email>" + recipientEmail + "</email>" +
"<name>" + recipientName + "</name>" +
"<roleName>Signer</roleName>" +
"</signer>" +
"</signers>" +
"</recipients>" +
"</inlineTemplate>" +
"</inlineTemplates>" +
"<document>" +
"<name>" + documentName + "</name>" +
"<documentId>1</documentId>" +
"</document>" +
"</compositeTemplate>" +
"</compositeTemplates>" +
"</envelopeDefinition>";
The error message you quoted:
DocumentId specified in the tab element does not refer to a document in this envelope. Tab refers to DocumentId 41791752 which is not present.
I suggest that the template is referring to that documentId. But you're registering your document as Id 1.
Try changing
"<documentId>1</documentId>" +
to
"<documentId>41791752</documentId>" +

how to know whether compatibility is on or off using asp.net(c#)

I have to do if user's browser compatibility is on then need to show message to user that your browser's compatibility is on.
I have searched this a lot on google but yet not found a proper answer.
I have tried below code but HttpContext.Current.Request.UserAgent always contains MSIE 7.0
string isOn = string.Empty;
if (HttpContext.Current.Request.UserAgent.IndexOf("MSIE 7.0") > -1)
{
isOn = "IE8 Compatibility View";`
}
else
{
isOn = "IE8";
}
}
You may try like this
if (Request.Browser.Type.ToUpper().Contains("IE"))
{
if (Request.Browser.MajorVersion < 7)
{
//Show the message here
}
...
}
else if (Request.Browser.Type.Contains("Firefox"))
{
//code to show message
}
else if (Request.Browser.Type.Contains("Chrome"))
{
//code to show message
}
Also check this MSDN which has its own way of detecting the browser
Query the Browser property, which contains an HttpBrowserCapabilities
object. This object gets information from the browser or client device
during an HTTP request, telling your application the type and level of
support the browser or client device offers. The object in turn
exposes information about browser capabilities using strongly typed
properties and a generic name-value dictionary.
private void Button1_Click(object sender, System.EventArgs e)
{
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
TextBox1.Text = s;
}

Save HTML EDITOR CONTENT to Content-type .DOCX in C#

private void ConvertHTMLtoDOCX(string txtcode)
{
System.Text.StringBuilder strBody = new System.Text.StringBuilder("");
strBody.Append("<html " + "xmlns:o='urn:schemas-microsoft-com:office:office' " + "xmlns:w='urn:schemas-microsoft-com:office:word'" + "xmlns='http://www.w3.org/TR/REC-html40'>" + "<head><title>Time</title>");
//The setting specifies document's view after it is downloaded as Print
//instead of the default Web Layout
strBody.Append("<!--[if gte mso 9]>" + "<xml>" + "<w:WordDocument>" + "<w:View>Print</w:View>" + "<w:DoNotOptimizeForBrowser/>" + "</w:WordDocument>" + "</xml>" + "<![endif]-->");
strBody.Append("<style>" + "<!-- /* Style Definitions */" + "#page Section1" + " {size:8.5in 11.0in; " + " margin:1.0in 1.25in 1.0in 1.25in ; " + " mso-header-margin:.5in; " + " mso-footer-margin:.5in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;}" + "-->" + "</style></head>");
strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" + "<div class=Section1>" + Html_editor.Content + "</div></body></html>");
//Force this content to be downloaded
//as a Word document with the name of your choice
string FullFilePath = #"C:\Users\ravikant\Desktop\AR GitHub\07-05-2014\FinalTestARGithub\LetterTemplate\"+ txtcode+ ".docx";
FileInfo file = new FileInfo(FullFilePath);
if (file.Exists)
{
ClientScript.RegisterStartupScript(this.GetType(), "disExp", "<script>alert('File Already Exists');</script>");
}
else
{
Response.AppendHeader("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
Response.AppendHeader("Content-disposition", "inline; filename="+txtcode+".docx");
Response.Write(strBody);
}
}
Here is the code using the CONTENT-TYPE for .DOCX "application/vnd.openxmlformats-officedocument.wordprocessingml.document", the Content is corrupt while opening the file.
Try this to find out what is going on with the file.
I've done this with native word .docx, but not .docx generated in this manner, so it may or may not work.
Make a copy of the saved file, change its extention from .docx to .zip.
Try and open that. We are trying to find a file document.xml, which is normally in the "word" folder.
Open that in a text editor an see if anything is jumping out as wrong or try putting it through an XML validator. VisualStudio should be good enough to show any malformating.
Online XML Validator that might help: http://www.xmlvalidation.com/
The following lines are also suspect:
strBody.Append("<!--[if gte mso 9]>" + "<xml>" + "<w:WordDocument>" + "<w:View>Print</w:View>" + "<w:DoNotOptimizeForBrowser/>" + "</w:WordDocument>" + "</xml>" + "<![endif]-->");
As I'm unsure how word will handle IE conditional comments. Comment out or remove this line and see what happens.
strBody.Append("<style>" + "<!-- /* Style Definitions */" + "#page Section1" + " {size:8.5in 11.0in; " + " margin:1.0in 1.25in 1.0in 1.25in ; " + " mso-header-margin:.5in; " + " mso-footer-margin:.5in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;}" + "-->" + "</style></head>");
Due to the nested comments. <!-- /* */-->. Perhaps try changing it to: strBody.Append("</head>"); and see if that works.

Scripts tags are getting executed even after encoding in asp.net

I am using HttpUtility.HtmlEncode(input) to encode the html script tags to prevent XSS..
the encoding is working but when the content gets dislpalyed on the browser the scripts are running..
here's my code,
<address>" + HttpUtility.HtmlEncode(dr["Street"]) + ", " + HttpUtility.HtmlEncode(dr["City"]) + ", " + HttpUtility.HtmlEncode(dr["State"]) + ", " + dr["ZipCode"] + "</address>"
in the dr["Street"] I am passing "alert('fdsf')"

How to search Complex Arraylist & Insert at given point

I am trying to create a simple appplication that can read from a text file and write to the text file. I have a main form which is shown below, also i have a secondary form also shown below; there are also getter and setter classes for Customers, accounts and Transactions. What i would like to do is search for a Customer based on any data held, but mostly there account number. How would i get it to return the correct customer with ALL of there information. Linked to this it would be good to use the search as a point for inserting say a new account.
Below is the main form for pritning out the customer and getting the information from the file.
//create account if all ok
if (allInputOK)
{
//create Account
Account temp = new Account(tempAccSortCode, tempAccNumber, tempAccNickName, tempAccDate, tempAccCurBal, tempAccOverDraft, tempNumTrans);
//add to array
Form1.accDetails.Add(temp);
//finish up
MessageBox.Show("Success Account added ");
resetForm();
}
}
foreach (Customer c in bankDetails)
{
lstOutput.Items.Add(" ");
lstOutput.Items.Add(c.getCustomerNumber() + " " + c.getCustomerTitle() + " " + c.getFirstName()
+ " " + c.getInitials() + " " + c.getSurname() + " " + c.getDateOfBirth()
+ " " + c.getHouseNameNumber() + " " + c.getStreetName() + " " + c.getArea()
+ " " + c.getCityTown() + " " + c.getCounty() + " " + c.getPostcode()
+ " " + c.getPassword() + " " + c.getNumberAccounts());
foreach (Account a in c.Accounts)
{
lstOutput.Items.Add("\t" + a.getAccSort() + " " + a.getAccNumber() + " " + a.getAccNick() + " " + a.getAccDate()
+ " " + a.getAccCurBal() + " " + a.getAccOverDraft() + " " + a.getAccNumTrans());
foreach (Transaction t in a.Transactions)
{
lstOutput.Items.Add("\t \t" + t.getDate() + " " + t.getType() + " " + t.getDescription() + " " + t.getAmount()
+ " " + t.getBalAfter());
}
}
}
In the above code for adding an account, where is adds it to the class Account and the arraylist i think is incorrect with the rest of the program on the main form which uses an underlying list to store the customer information and there accounts/transactions.
EDIT: the above code snippet shows the adding of a new account, however it doesnt seem to be working as i need to find the correct customer by searching the customer array, and then inserting it into the correct place. The second snippet of code shows the arraylist with the underlying lists connected to each customer.
Where to begin?
Generally, for querying objects you can use Linq to Objects.
Also, I would recommend against using text files to keep track of things. They are fine at first, but quickly grow unwieldy and slow. On top of that, what if your app crashes before you saved? Look into a "light database" like SQLite (yes, that's one 'L').

Categories