Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7039459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:48:03+00:00 2026-05-28T01:48:03+00:00

I am developing silverlight web part by using the client object model. I am

  • 0

I am developing silverlight web part by using the client object model. I am getting the bitmap image from sharepoint server. Now I want to save this bitmap image in isolated storage. So I am using following code

 WriteableBitmap wb = new WriteableBitmap(attachments);

 using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
 {
     using (IsolatedStorageFileStream isoStream =
     new IsolatedStorageFileStream("abcd1.jpg", FileMode.Create, isoFile))
     {
         using (StreamWriter sw = new StreamWriter(isoStream))
         {
             sw.Write(wb.ToByteArray());
         }
     }
 }

Now I am seeing the saved image at location C:\Users\Rent2\AppData\LocalLow\Microsoft\Silverlight\is\vzvpufsm.s4i\m0laonzr.til\1\s\nkhajster01es5wdoyfxd0n5rd2dls3ovyu4wcdig04zjx44hyaaafea\f

When I click on it, it gives me message as “Invalid Image”. Can you please tell me how should i write code so that I can see the actual image after saving it in isolated storage ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:48:04+00:00Added an answer on May 28, 2026 at 1:48 am
        private void zipFile()
                {     
                    context = Microsoft.SharePoint.Client.ClientContext.Current;
                    Microsoft.SharePoint.Client.File.OpenBinaryDirect(
                            context,
                            @"/TemplateInvoice/" + App.templateFileName + ".xlsx", successFile, FailFile);                  
                }
    
        private void successFile(object sender, OpenBinarySucceededEventArgs args)
                {
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        // Obtain the isolated storage for an application.
                        try
                        {
                            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                            {
                                Stream strm = args.Stream;
    
                                using (var isoStream = store.OpenFile(App.templateFileName + ".zip", FileMode.OpenOrCreate))
                                {
                                    // Read the resource file into a byte array.
                                    bytes = new byte[strm.Length];
                                    int numBytesToRead = (int)strm.Length;
                                    int numBytesRead = 0;
                                    while (numBytesToRead > 0)
                                    {
                                        // Read may return anything from 0 to numBytesToRead.
                                        int n = strm.Read(bytes, numBytesRead, numBytesToRead);
                                        // The end of the file is reached.
                                        if (n == 0)
                                            break;
                                        numBytesRead += n;
                                        numBytesToRead -= n;
                                    }
    
    
                                    numBytesToRead = bytes.Length;
    
                                    // Write the byte array to the IsolatedStorageFileStream.
                                    isoStream.Write(bytes, 0, numBytesToRead);
                                    //isoStream.Dispose();
                                }
    
                                strm.Close();
    
                                string path = App.templateFileName + ".zip";
                                ZipHelp.UnZip(path, System.IO.Path.GetDirectoryName(path), 4096);
    
                                replaceFileContent();
    
                                string rootDirectory = System.Windows.Browser.HttpUtility.UrlDecode(path);
                                string fileName = ZipHelp.Zip(rootDirectory.Replace(".zip", ""), invoice);
    
                                //string filename = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "Invoice1.xlsx";
    
                                // Read the resource file into a byte array.
                                using (var stream = store.OpenFile(fileName, FileMode.Open))
                                {
    
                                    bytes = new byte[stream.Length];
                                    int numBytesToRead = (int)stream.Length;
                                    int numBytesRead = 0;
                                    while (numBytesToRead > 0)
                                    {
                                        // Read may return anything from 0 to numBytesToRead.
                                        int n = stream.Read(bytes, numBytesRead, numBytesToRead);
                                        // The end of the file is reached.
                                        if (n == 0)
                                            break;
                                        numBytesRead += n;
                                        numBytesToRead -= n;
                                    }
    
    
                                    InvoiceTemplete invoiceTemplate = new InvoiceTemplete(fileName, bytes, SetMessage);
                                    invoiceTemplate.AddDocument(invoiceTemplate);
                                }
    
                            }
    
                            //mark rows as billed
                            foreach (var item in PrivatePayList)
                            {
                                MedwaiverViewModel MedwaiverViewModelObj = new MedwaiverViewModel();
                                MedwaiverViewModelObj.ChangeBillingStatus(item.ListItemId, "Billed");
    
                                if (MedwaiverTimeLogList != null)
                                {
                                    MedwaiverTimeLogList.Remove(item);
                                }
    
                                if (ClientSpecificTimeLogList != null)
                                {
                                    ClientSpecificTimeLogList.Remove(item);
                                }
    
                                if (rangeBoundTimeLogListForDate != null)
                                {
                                    rangeBoundTimeLogListForDate.Remove(item);
                                }
    
                                if (vRangeBoundTimeLogListForDateAndClient != null)
                                {
                                    vRangeBoundTimeLogListForDateAndClient.Remove(item);
                                }
    
                            }
    
                        }
                        catch (IsolatedStorageException isx)
                        {
                            MessageBox.Show(isx.Message);
                        }
                    });
                }
    
         private void FailFile(object sender, OpenBinaryFailedEventArgs e)
                {
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("Fail");
                    });
                }
    
    
    //The following class zip and unzip the file
    
    class ZipHelp
        {
            static List<string> folderPathList = new List<string>();      
    
            public static string Zip(string rootDirectory, string fileName)
            {
                byte[] buffer;
    
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    IsolatedStorageFileStream zipFileStream = store.CreateFile(fileName + ".xlsx");
                    ZipOutputStream zipOutStream = new ZipOutputStream(zipFileStream);
                    zipOutStream.UseZip64 = UseZip64.Off;
                    //zipOutStream.CanPatchEntries
    
                    foreach (var item in folderPathList)
                    {
                        string entryName = "";
    
                        buffer = new byte[4096];
    
                        if (item.Substring(0,1) == @"/")
                        {
                            //removes leading /
                            entryName = item.Substring(1);
                        }
                        else
                        {
                            entryName = item;
                        }
    
                        ZipEntry entry = new ZipEntry(entryName);
                        //entry.CompressionMethod = CompressionMethod.Deflated;
                        //entry.
                        entry.IsZip64Forced();
                        //entry.IsDirectory
    
    
    
                        zipOutStream.PutNextEntry(entry);
    
    
                        using (IsolatedStorageFileStream stream = store.OpenFile(rootDirectory + @"\" + item, FileMode.Open))
                        {
    
    
    int size;
                            do
                            {
                                size = stream.Read(buffer, 0, buffer.Length);
                                zipOutStream.Write(buffer, 0, size);
                            } while (size > 0);
    
                        stream.Close();
                    }
                }
    
                zipOutStream.Close();
                zipFileStream.Close();
            }
    
            return fileName + ".xlsx";
    
    
            //string[] directories = GetLocationTypes();
    
            //zip();
    
            //string[] filenames = Directory.GetFiles(directories);
    
            //using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            //{                
            //    using (var isoStream = store.OpenFile("@" + rootDirectory, FileMode.OpenOrCreate))
            //    {
            //        //foreach(string dir in 
            //    }
            //}
        }       
    
        private static string[] GetLocationTypes()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                return store.GetDirectoryNames();
            }
    
        }
    
        /// <summary>
        /// UnZip a file
        /// </summary>
        /// <param name="SrcFile">source file path</param>
        /// <param name="DstFile">unzipped file path</param>
        /// <param name="BufferSize">buffer to use</param>
        public static void UnZip(string SrcFile, string DstFile, int BufferSize)
        {
            folderPathList.Clear();
    
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
            FileStream fileStreamIn = store.OpenFile(SrcFile, FileMode.Open, FileAccess.Read);
    
            ZipInputStream zipInStream = new ZipInputStream(fileStreamIn);
            string rootDirectory = System.Windows.Browser.HttpUtility.UrlDecode(SrcFile);
            rootDirectory = rootDirectory.Replace(".zip", "");
            store.CreateDirectory(rootDirectory);
    
            while (true)
            {
                ZipEntry entry = zipInStream.GetNextEntry();
    
                if (entry == null)
                    break;
    
                if (entry.Name.Contains("/"))
                {
                    string[] folders = entry.Name.Split('/');
    
                    string lastElement = folders[folders.Length - 1];
                    var folderList = new List<string>(folders);
                    folderList.RemoveAt(folders.Length - 1);
                    folders = folderList.ToArray();
    
                    string folderPath = "";
                    foreach (string str in folders)
                    {
                        folderPath = folderPath + "/" + str;
                        if (!store.DirectoryExists(rootDirectory + "/" + folderPath))
                        {
                            store.CreateDirectory(rootDirectory + "/" + folderPath);
                        }
                    }
    
                    folderPath = folderPath + "/" + lastElement;
                    writeToFile(BufferSize, fileStreamIn, zipInStream, rootDirectory, folderPath);
    
                }
                else
                {
                    writeToFile(BufferSize, fileStreamIn, zipInStream, rootDirectory, entry.Name);
                }
    
            }
    
            zipInStream.Close();
            fileStreamIn.Close();
    
        }
    
        private static void writeToFile(int BufferSize, FileStream fileStreamIn, ZipInputStream zipInStream, string rootDirectory, string folderPath)
        {
            IsolatedStorageFile store1 = IsolatedStorageFile.GetUserStoreForApplication();
            FileStream fileStreamOut = store1.OpenFile(rootDirectory + "/" + folderPath, FileMode.Create, FileAccess.Write);
    
            folderPathList.Add(folderPath);
    
            int size;
            byte[] buffer = new byte[BufferSize];
            do
            {
                size = zipInStream.Read(buffer, 0, buffer.Length);
                fileStreamOut.Write(buffer, 0, size);
            } while (size > 0);
    
    
            fileStreamOut.Close();
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing silverlight web part for sharepoint 2010. I have an xml file
I am developing a Silverlight web part for Sharepoint 2010. I have a button
I am developing silverlight web part for sharepoint 2010. In my project I have
I'm developing a small web application using Microsoft Silverlight 3. I'm using Microsoft Expressin
At the moment I'm developing a web based application using Silverlight 3.0. For the
I am developing a web app using silverlight. I read that Microsoft offers 10
I've been developing web apps for over a decade now, all the way from
I'm developing a web page for a customer using the Silverlight application for dynamic
I am developing silverlight web part. I have a one List Entry log. In
I am developing a Silverlight web app and am working now on a child

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.