We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Silverlight docio read from Isolated Storage

Thread ID:

Created:

Updated:

Platform:

Replies:

92954 Feb 16,2010 08:52 AM UTC Feb 20,2018 12:32 PM UTC ASP.NET Web Forms (Classic) 8
loading
Tags: DocIO
Nalwi
Asked On February 16, 2010 08:52 AM UTC

I have word document template (.doc) stored in the isolated storage
which I am trying to read as in-memory file stream using docio in a Silverlight client application and populate the bookmarks in it.
Is this technically feasible with docio?

Poornima R [Syncfusion]
Replied On February 17, 2010 11:28 AM UTC

Hi Nalwi,

Thank you for your interest in Syncfusion Products.

We have prepared the sample for your requirement.Could you please find the sample from the below link and let us know if this helps.

Sample link:
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=F92954143833327.zip

Please let us know if you have any queries.

Regards,
Poornima

Nalwi
Replied On February 21, 2010 01:17 AM UTC

Thanks for this sample. However my requirement was to read .doc file from silverlight isolatedstorage.
However my question is reading a .doc file from isolatedstorage as a IsolatedStorageFileStream and then use docIO api to replace bookmarks and save back to isolatedstorage in a silverlight3 application. Is this possible?

Nalwi
Replied On February 21, 2010 10:13 AM UTC

I got this working. And I am posting the code here for anyone having the same requirement.

var buffer = IsolatedStorageHelper.ReadFileFromIsolatedStorage
(filename);
WordDocument document;
using (Stream stream = new MemoryStream(buffer))
{
document = new WordDocument(stream,
FormatType.Doc);
}
var bn = new BookmarksNavigator(document);
bn.MoveToBookmark("Bookmark1");
//Getting first book mark content
var bookmarkContent1 = bn.GetBookmarkContent();
bn.MoveToBookmark("Bookmark2");
//Replacing the second bookmark content with first
//bookmark content
bn.ReplaceBookmarkContent(bookmarkContent1);
using (var writer = new MemoryStream())
{
document.Save(writer, FormatType.Doc);
IsolatedStorageHelper.StoreFileToIsolated
(filename, writer.GetBuffer());
}

And my isolated storage helper class looks as follows

public static byte[] ReadFileFromIsolatedStorage(string
fileName)
{
byte[] retVal;

using (IsolatedStorageFile iso =
IsolatedStorageFile.GetUserStoreForApplication())
{
if (iso.FileExists(fileName))
{
using (IsolatedStorageFileStream stream =
iso.OpenFile(fileName, FileMode.Open))
{
retVal = new byte[stream.Length];
stream.Read(retVal, 0, retVal.Length);
}
}
else
{
retVal = new byte[0];
}
}
return retVal;
}


public static void StoreFileToIsolated(string path, byte
[] data)
{
var iso =
IsolatedStorageFile.GetUserStoreForApplication();
using (var isoStream = new IsolatedStorageFileStream
(path, FileMode.Create, iso))
{
isoStream.Write(data,0,data.Length);
}
}




Poornima R [Syncfusion]
Replied On February 22, 2010 12:12 PM UTC

Hi Nalwi,

Thank you for your update.

We are glad that you have found the result by yourself.

Please let us know if you have any further queries.

Regards,
Poornima

Eliza Sahoo
Replied On June 11, 2010 11:19 AM UTC

We can use Isolated Storage as a virtual file system to store data in a hidden folder on our machine in silverlight application. Silverlight application is allocated the storage of 1 MB per application but we can increase the amount of storage.
This is the function to get the data in the isolated storage

Private Function LoadData(ByVal fileName As String) As String
Dim data As String = String.Empty
Dim isfstream As New IsolatedStorageFileStream(fileName, FileMode.Open, IsolateStorageFileObj)
Dim sr As New StreamReader(isfstream)
data = sr.ReadLine()
Return data
End Function

http://www.mindfiresolutions.com/Isolated-storage-in-Silverlight-application-557.php

Poornima R [Syncfusion]
Replied On June 15, 2010 09:46 AM UTC

Hi Eliza,

Thank you for your information.

Please let us know if you have any queries.

Regards,
Poornima

oktay
Replied On February 19, 2018 09:44 AM UTC

I got this working. And I am posting the code here for anyone having the same requirement.

var buffer = IsolatedStorageHelper.ReadFileFromIsolatedStorage
(filename);
WordDocument document;
using (Stream stream = new MemoryStream(buffer))
{
document = new WordDocument(stream,
FormatType.Doc);
}
var bn = new BookmarksNavigator(document);
bn.MoveToBookmark("Bookmark1");
//Getting first book mark content
var bookmarkContent1 = bn.GetBookmarkContent();
bn.MoveToBookmark("Bookmark2");
//Replacing the second bookmark content with first
//bookmark content
bn.ReplaceBookmarkContent(bookmarkContent1);
using (var writer = new MemoryStream())
{
document.Save(writer, FormatType.Doc);
IsolatedStorageHelper.StoreFileToIsolated
(filename, writer.GetBuffer());
}

And my isolated storage helper class looks as follows

public static byte[] ReadFileFromIsolatedStorage(string
fileName)
{
byte[] retVal;

using (IsolatedStorageFile iso =
IsolatedStorageFile.GetUserStoreForApplication())
{
if (iso.FileExists(fileName))
{
using (IsolatedStorageFileStream stream =
iso.OpenFile(fileName, FileMode.Open))
{
retVal = new byte[stream.Length];
stream.Read(retVal, 0, retVal.Length);
}
}
else
{
retVal = new byte[0];
}
}
return retVal;
}


public static void StoreFileToIsolated(string path, byte
[] data)
{
var iso =
IsolatedStorageFile.GetUserStoreForApplication();
using (var isoStream = new IsolatedStorageFileStream
(path, FileMode.Create, iso))
{
isoStream.Write(data,0,data.Length);
}
}




ttt

Mohanaselvam  Jothi [Syncfusion]
Replied On February 20, 2018 12:32 PM UTC

Hi Oktay,

Thank you for your update.

Yes, you can use the mentioned code snippets to read a Word document using IsolatedStorage, then replace the bookmark content using DocIO APIs and saves the Word document using IsolatedStorage in Silverlight application.

Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;