How to open OneNote document from SharePoint 2013?


#1

Our Company downloaded a trial version and is evaluating Aspose.Note to help us retrieving OneNote contents from SharePoint2013.
But we are in trouble for a correct access through Aspose.Note API:

my sample code (visual studio 2013):
var textFromFile = client.DownloadString(“http://dev/sites/OneNote/Test.one”);
byte[] byteArray = Encoding.UTF8.GetBytes(textFromFile);
MemoryStream stream = new MemoryStream(byteArray);
Aspose.Note.Document document = new Aspose.Note.Document(stream);

Aspose error:
System.NotSupportedException: ‘The specified path format is not supported’

Could you please help to provide a sample code for correct accessing OneNote files in Sharepoint or give advice on how we should do?


#2

@Jerry1019,
Could you please share complete stack trace and check if the source of this exception is Aspose.Note API or not. Make sure that the file is loaded ok into memory stream and use latest version of API. Share your template file for our analysis if problem persists.


#3

Our stack trace :
API ver 19.5
Aspose.Note.UnsupportedFileFormatException was unhandled by user code
HResult=-2146233088
Message=Unsupported file type.
Source=Aspose.Note
StackTrace:
於 . (Stream , String )
於 . (Stream , String , Boolean )
於 . (Stream , Document , LoadOptions )
於 Aspose.Note.Document. (Stream , LoadOptions )
於 Aspose.Note.Document…ctor(Stream inStream, LoadOptions loadOptions)
於 Aspose.Note.Document…ctor(Stream inStream)
於 ConsoleApplication1.Program.b__0() 於 d:\test\ConsoleApplication1\ConsoleApplication1\Program.cs: 行 169
於 Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.b__3()
於 Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
InnerException:


#4

@Jerry1019,
Please also share your sample file for our testing.


#5

OneNoteTest.zip (827.2 KB)
Our Sample File


#6

@Jerry1019,
This seems to be the issue with the byte array you are creating. Following code works fine and file is loaded successfully. You may try to prepare the byte array similar to the one created in the following code and try the scenario again.

byte[] byteArray = File.ReadAllBytes(path + "Test.one");
MemoryStream stream = new MemoryStream(byteArray);
Aspose.Note.Document document = new Aspose.Note.Document(stream);

#7

Our file is put on sharepoint document library not in local.
The sample looks like read file from local, this seems ok, but when reading file from sharepoint document library in “http”, it happend error.


#8

@Jerry1019,
Could you please share the downloaded string as it is by saving it in some file and then share with us for our reference. We need exact string which you get after download before converting it to byte array.


#9

@ahsaniqbalsidiqui

WebClient client = new WebClient();
var textFromFile = client.DownloadString(“http://dev/sites/OneNote_Doc/OneNoteTest/test.one”);

File.WriteAllText(@“D:\test.txt”, textFromFile);

test.zip (790.4 KB)


#10

@Jerry1019,
You may try to read the file from share point using OpenBinary function as shown in the following sample code and share the feedback.

using (SPSite docsite = new SPSite(uploadedDocPath))
{
    using (SPWeb docweb = docsite.OpenWeb())
    {
        SPListItem item = docweb.GetListItem(uploadedDocPath);
        SPFile objspFile = item.File;

        byte[] byteArray = objspFile.OpenBinary();

        MemoryStream stream = new MemoryStream(byteArray);
        stream.Position = 0;
        // specify loadOptions for Aspose.Note.LoadOptions......
        Aspose.Note.Document document = new Aspose.Note.Document(stream, loadOptions);
    }
}

#11

It’s seems ok.
thanks.

By teh way, how can I open .onetoc2 use the Aspose.Note.NoteBook


#12

@Jerry1019,
You can simply pass the file name to constructor of Notebook class. See the document with example code for your reference:
https://docs.aspose.com/display/notenet/Working+with+OneNote+NoteBook#WorkingwithOneNoteNoteBook-LoadingNotebookFile


#13

I try the above code to read “.onetoc2” in sharepoint, but it not work.


#14

@Jerry1019,
I have tried to load a .onetoc2 and observed that it works fine. Could you please share your downloaded stream which is a .onetoc2 file by saving your MemoryStream into a file for our testing? We will check it and share our feedback.


#15
SPListItem item = clsWeb.GetListItem(sUrl);

SPFile objFile = item.File;

byte[] byteArray = objFile.OpenBinary();

MemoryStream stream = new MemoryStream(byteArray);
stream.Seek(0, SeekOrigin.Begin);

using (FileStream fs = new FileStream(@"D:\output.txt", FileMode.OpenOrCreate))
{
    stream.CopyTo(fs);
    fs.Flush();
}

output.zip (1.1 KB)


#16

@Jerry1019,
Please share the .onetoc2 file here for our testing. You can write the stream to file so that we can analyze further with your data.


#17

the file output.zip is .onetoc2 file openBinary in sharepoint save to file from stream


#18

@Jerry1019,
I have tested this file zipped in output.zip as .ONETOC2 file but it is not working fine. As you know that .onetoc2 is a Microsoft OneNote index file that stores information about the order of note-taking sections therefor this file alone may not be of much use. There shall be .ONE files along with this index file to open them properly. You may please try to download the files using some other tool and check if Microsoft OneNote opens them successfully or not. Once confirmed, you may try using Aspose.Note to perform the same task. If some issue is observed, share the downloaded file with us which we will use for our analysis.


#19

I have download file from Sharepoint Document Library with windows Explore.
When I open .onetoc2, something happened, it can’t edit, until transfer to 2010.
download files in zip.
OneNoteTest.zip (828.4 KB)


#20

@Jerry1019,
I have noticed exception when opening the .onetoc2 file. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

NOTENET-2878 - Problem opening onetoc2 files