Extracting note content from OneNote using XmlDocument Class - vb.net

I am using vb.net and trying to extract the text out of a note in onenote (I'll settle for OneNote2010 or 2016.) The following code is capable of copying the titles of the books, and the names of the sections... to a text box (for testing), but not the actual content of the note. I know this is probably something VERY easy once you know how to do it once. But I for the life of me/google search can not figure out the magic command. (In Visual Basic).
Thank you for reading!
Imports Microsoft.Win32
Imports System.Security.Permissions
Imports Microsoft.Office.Interop
Imports System.Xml
Public Class Form1
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim strNamespace As String = "http://schemas.microsoft.com/office/onenote/2013/onenote"
Dim outputXML As String
Dim onApplication As OneNote.Application = New OneNote.Application
onApplication.GetHierarchy(Nothing, OneNote.HierarchyScope.hsSections, outputXML)
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.LoadXml(outputXML)
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NameTable)
nsmgr.AddNamespace("one", strNamespace)
Dim Testa As XmlNode = xmlDoc.SelectSingleNode("//one:Section[#name='TestNote']", nsmgr)
TextBox1.Text = outputXML
End Sub
End Class

To get page content, you will need to call onApplication.GetPageContent() with the appropriate pageID.
Look at the resulting XML. You will probably need to look for every one:T element, and concatenate. You will have to look for one:Bullet and one:Number for lists.
Here's the XSD that describes all the elements.
https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/63/17/0336.OneNoteApplication_2013_xsd.txt

Related

Event 'Load' cannot be found

Getting the error "Event 'Load' cannot be found" referring to "Handles MyBase.Load" Please see attached code. Any help much appreciated!
I have many other applications set up the same way and they all work. However, these were in an older version of Visual Studio.
Option Explicit On
Option Strict On
Imports System, System.IO
Imports System.Text
Public Class Form1
Private Sub cleanXMLDialog_Load(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles MyBase.Load
Main()
End
End Sub
Public Sub Main()
Dim directories() As String = Directory.GetDirectories("C:\")
Dim files() As String = Directory.GetFiles("C:\", "*.dll")
DirSearch("c:\")
End Sub
Sub DirSearch(ByVal sDir As String)
Dim d As String
Dim f As String
Try
For Each d In Directory.GetDirectories(sDir)
For Each f In Directory.GetFiles(d, "*.xml")
'Dim Response As String = MsgBox(f)
Debug.Write(f)
Next
DirSearch(d)
Next
Catch excpt As System.Exception
Debug.WriteLine(excpt.Message)
End Try
End Sub
End Class
Load should happen without this error.
This is the class declaration:
Public Class Form1
It looks like you intend this to inherit from a windows Form type, but there's nothing here to make that happen.
You may want this:
Public Class Form1 Inherits System.Windows.Forms.Form
but even this is unlikely to really accomplish anything. It's not enough just to inherit from the Form type if you don't have any controls are properties set and don't ever show the form.
Did you accidentally create a Console or Class Library project when you mean to create a WinForms project?

EMGUCV facial recognition issue in VB.NET

I'm trying to implement a web app with VB.NET which is supposed to perform facial recognition on images in a folder using EMGUCV library. Anyway, when I call method train on the facerecognizer object a strange exception is raised:
'OpenCV: 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows
Here's my test code:
Imports System.Drawing
Imports Emgu.CV
Imports Emgu.CV.Face
Imports Emgu.CV.Structure
Imports Emgu.CV.Util
Public Class _Default
Inherits Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim images As New Mat
Dim Palb0 = "c://IMGDB//Alberto//0.jpg"
Dim Palb1 = "c://IMGDB//Alberto//1.jpg"
Dim Pcon0 = "c://IMGCONFRONTO//0.jpg"
images.PushBack(CvInvoke.Imread(Palb0, CvEnum.LoadImageType.Grayscale))
images.PushBack(CvInvoke.Imread(Palb1, CvEnum.LoadImageType.Grayscale))
Dim model = New EigenFaceRecognizer(80, Double.PositiveInfinity)
Dim labels As New VectorOfInt
Dim a(0) As Integer
a(0) = 0
labels.Push(a)
model.Train(images, labels)
Dim imgConf As Mat
imgConf = CvInvoke.Imread(Pcon0, CvEnum.LoadImageType.Grayscale)
model.Predict(imgConf)
Dim PR As FaceRecognizer.PredictionResult
Dim dst = PR.Distance
Dim lbl = PR.Label
MsgBox(dst)
End Sub
End Class
I tryed nearly everything but can' solve it. Any help will be really appreciated.
I managed to find a solution myself.
The roblem was really as simpe as the type of object I used for the constructor. It was supposed to be a VectorOfMat instead of Mat. the class couldn't work because it expected an array.
Dim images As New VectorOfMat
Another problem was in the constructor itself. It was supposed to be:
Dim model As New EigenFaceRecognizer(80, Double.PositiveInfinity)
One more piece of advice: If the train method doesen't receive an array of mat of at least two images, it will throw another exception. The images are supposed to be of the same size or (strange) the object will throw one more exception.
Finally the correct code for the predictionresult is:
Dim PR As FaceRecognizer.PredictionResult = model.Predict(imgConf)
and you get eigenfaces prediction distance:
Dim dis = PR.Distance
Hope this can get somebody out of trouble.
Ceers.

vb.net XmlDocument.SelectSingleNode and xmlNamespace issue

I am trying to get this code working but somehow is not getting the content
My Code
Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode
'Create the XML Document
m_xmld = New XmlDocument()
'Load the Xml file
m_xmld.Load("http://feeds.thescore.com/nfl.rss")
'Get the list of name nodes
m_nodelist = m_xmld.SelectNodes("/rss/channel/item")
Dim content As XmlNamespaceManager = New XmlNamespaceManager(m_xmld.NameTable)
content.AddNamespace("content", "http://schemas.xmlsoap.org/soap/envelope/")
'Loop through the nodes
For Each m_node In m_nodelist
If Not m_node.SelectSingleNode("content:encoded",content) Is Nothing AndAlso Len(m_node.SelectSingleNode("content:encoded",content).InnerText) > 0 Then
response.Write(m_node.SelectSingleNode("content:encoded",content))
response.Flush()
end if
Next
Can someone help me please?
I did it this way and could see all of the content nodes, that appear to be html.
Imports <xmlns:atom="http://www.w3.org/2005/Atom">
Imports <xmlns:content="http://purl.org/rss/1.0/modules/content/">
Imports <xmlns:dc="http://purl.org/dc/elements/1.1/">
Imports <xmlns:georss="http://www.georss.org/georss">
Imports <xmlns:media="http://search.yahoo.com/mrss/">
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xe As XElement = XElement.Load("http://feeds.thescore.com/nfl.rss")
Dim ie As IEnumerable(Of XElement) = xe...<content:encoded>
For Each c As XElement In ie
Debug.WriteLine(c.Value)
Next
End Sub
End Class
I managed with different approach I import first the data with webClient replaced the with and worked like a charm

Error with DotNetOpenAuth2 with VB.Net

My new project demands the implementation OpenAuth. Following is my code.
The line
scopes.Add(CalendarService.Scopes.Calendar.GetStringValue())
in the GetAuthorization gives the following error.
Overload resolution failed because no accessible...
GetStringValue is the most specific for these argument. I can understand that GetStringValue is not the method/argument found in the calendarservice.scopes.calendar but my question is why so? I have downloaded this code from some website and most website is giving example in C# but there are hardly any site that is showing any example in VB.Net. Can anyone help me here.
Regards
P.S. I am using Visual Studio 2008.
Imports System
Imports System.Diagnostics
Imports DotNetOpenAuth.OAuth2
Imports Google.Apis.Authentication.OAuth2
Imports Google.Apis.Authentication.OAuth2.DotNetOpenAuth
Imports Google.Apis.Calendar.v3
Imports Google.Apis.Util
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Tasks.v1
Imports Google.Apis.Tasks.v1.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim provider = New NativeApplicationClient(GoogleAuthenticationServer.Description)
provider.ClientIdentifier = "Client ID Here"
provider.ClientSecret = "Client Secret Here"
Dim auth = New OAuth2Authenticator(Of NativeApplicationClient)(provider, AddressOf GetAuthorization)
Dim service = New CalendarService(auth)
Dim first = service.CalendarList.List.Fetch().Items().First()
Label1.Text = first.Summary
End Sub
Private Function GetAuthorization(ByVal arg As NativeApplicationClient) As IAuthorizationState
Dim scopes As New System.Collections.Generic.List(Of String)
scopes.Add(CalendarService.Scopes.Calendar.GetStringValue())
Dim state As IAuthorizationState = New AuthorizationState(scopes)
state.Callback = New Uri(NativeApplicationClient.OutOfBandCallbackUrl)
Dim authUri As Uri = arg.RequestUserAuthorization(state)
Process.Start(authUri.ToString())
' Open a modal dialogue for user to paste the authorization code from Browser = authCode
Dim authCode As String = Console.ReadLine()
Return arg.ProcessUserAuthorization(authCode, state)
End Function
End Class
GetStringValue is en extension method defined on Google.Apis.Util.Utilities.
Similar VB.NET code to this worked for me on VS2012 with the latest version of the library.
You can find my VB.NET sample in https://codereview.appspot.com/7007048/, but it still wasn't approved, so be careful using it.
In the samples repository (http://code.google.com/p/google-api-dotnet-client/source/browse/?repo=samples#hg%2FDiscovery.VB.ListAPIs), there is currently only one VB.NET sample, but hopefully the sample above will be approved soon and it will be added to the repository.
Please elaborate more on the references that you have in your project and the stack trace.
It looks like there is another overloading to this GetStringValue somewhere else (http://msdn.microsoft.com/en-us/library/2hx4ayzs(v=vs.80).aspx) in your code or in a reference assembly.

Compressing a database to a single file?

In a contact manager program I've been storing data in CSV files for each contact and would like a way to compress this data into a single file.
I have attempted using data entry tools in the visual studio toolbox and template class, though I have never quite figured out how to use them. What would be especially convenient is if I could somehow store a generic class instance as opposed to having to come up with a string representation of it, and then parse it.
I'd also need to figure out how to tell the program what to do when a file is opened (I've noticed in the properties how to associate a file type with the program though am not sure how to tell it what to do when it's opened).
IMHO, switch to sqlite. You'll be able to query faster, compress it, and much more then working with a csv file.
Found this article about Serialization and it works very well!
http://www.vbdotnetheaven.com/UploadFile/Nimusoft/Serialization105022008052559AM/Serialization1.aspx
edit: Figured I should probably post more. I have a class IOwner, and list of this class contains all of my database. So I added serialization tags to this class and others it references then substitute in those properties with the ones shown on the article:
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO
Namespace BinarySerialization
<Serializable()> _
Public Class IFile
Implements ISerializable
Public Contacts As List(Of IOwner)
Public Self As IOwner
Public Cars As List(Of Vehicle)
Public path As String
Public Sub New()
End Sub
Public Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
Data.Self = info.GetValue("Self", GetType(IOwner))
Data.Contacts = info.GetValue("Contacts", GetType(List(Of IOwner)))
Data.Cars = info.GetValue("Cars", GetType(List(Of Vehicle)))
End Sub
Public Sub WriteFile()
Dim s As New FileStream(path, FileMode.Create, FileAccess.ReadWrite)
Dim B As New BinaryFormatter()
B.Serialize(s, Me)
s.Close()
End Sub
Public Function ReadFile() As IFile
Dim Fs As New FileStream(path, FileMode.Open, FileAccess.Read)
Dim F As New BinaryFormatter()
Dim s1 As IFile = DirectCast(F.Deserialize(Fs), IFile)
Fs.Close()
Return s1
End Function
#Region "ISerializable Members"
Public Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext) Implements ISerializable.GetObjectData
info.AddValue("Self", Data.Self)
info.AddValue("Contacts", Data.Contacts)
info.AddValue("Cars", Data.Cars)
End Sub
#End Region
End Class
End Namespace
UPDATE 2016
Binary serialization is not advisable for complex structures that are subject to change. Using a database storage method such as SQLite and using an ODB (object database model) would have been preferable.