0

so I am having this problem that I can't figure out at the moment. I have already Grabbed the patched Ionic.zip from "http://dotnetzip.codeplex.com/workitem/14049".

I tested my code on a non-silverlight project using the ionic.zip for regular c# and its working. But when modifying the code for silverlight(lightswitch) I keep on getting the 'IBM437' Error.

Here is what my code looks like

void selectFileWindow_Closed(object sender, EventArgs e)
{
    SelectFileWindow selectFileWindow = (SelectFileWindow)sender;
    string selectFileStream = sender.ToString();
    var parsedString = selectFileStream.Split(',');

    if (selectFileWindow.DialogResult == true && (selectFileWindow.myStream != null))
    {
        foreach (FileStream myZippedStream in selectFileWindow.myStream)
        {
            string zippedLocation = myZippedStream.Name;
            var parsedLocation = zippedLocation.Split('\\');
            string fileName = parsedLocation[parsedLocation.Length - 1];
            //filename is equal to something like "myfile.zip"
            // We want to turn that to "myfile.txt)
            fileName = (fileName.Substring(0, fileName.Length - 3)) + "txt";

            using (FileStream fs = File.Create("c:\\temp\\gftTempFile.txt"))
            {
                using (var ms = new MemoryStream())
                {
                    //ReadOptions myOptions = new ReadOptions();
                    //myOptions.Encoding = System.Text.Encoding.UTF8;
                    //using (ZipFile myZip = ZipFile.Read(myZippedStream, myOptions))
                    // I have tried using the commentted code but it gives the same error
                    using (ZipFile myZip = ZipFile.Read(myZippedStream))
                    {
                        ZipEntry myEntry = myZip[fileName];
                        myEntry.Extract(ms);

                        ms.WriteTo(fs);
                        fs.Close();

                        ImportGift.importGift(fs, this.DataWorkspace);

                        try
                        {
                            fs.Close();
                            fs.Dispose();
                            ms.Close();
                            ms.Dispose();
                            File.Delete("c:\\temp\\gftTempFile.txt");
                        }
                        catch { }
                    }
                }
            }
        }
        doneLoading = true;
    }
}

1 Answers1

0

I'm not sure error the "IBM437" is, or where in your code that happens, but I do know that SilverLight doesn't allow you to access the file system from code without showing a SelectFileWindow first.

In other words: your lines that have a hardcoded "c:\temp\gftTempFile.txt" will definitely not work in a SL app without elevated permissions.