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. Image for the cookie policy date
close icon

Silverlight docio read from Isolated Storage

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?

8 Replies

PR Poornima R Syncfusion Team 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


NA Nalwi 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?


NA Nalwi 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);
}
}





PR Poornima R Syncfusion Team 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


ES Eliza Sahoo 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


PR Poornima R Syncfusion Team 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


OK oktay replied to Nalwi 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


MJ Mohanaselvam Jothi Syncfusion Team 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
 


Loader.
Live Chat Icon For mobile
Up arrow icon