Question

I am new to wp7 development trying with a simple example ie..

I have an image control and 2 buttons one is for loading image and displaying it in the image control and the other is for saving that image to new folder which I need to create.

I have the below code and I am not getting any errors but the problem is I am unable to create the directory and save the existed image to that folder.

I am unable to see the directory as well as the Image after saving it.

Can we see the folder in the emulator(Or)It is only possible that we can see the created directory on the windows phone?

Imports System.IO
Imports Microsoft.Phone.Tasks
Imports System.IO.IsolatedStorage
Imports System.Windows.Media.Imaging

Partial Public Class Page1
    Inherits PhoneApplicationPage

    Public Sub New()
        InitializeComponent()
        photoChooserTask = New PhotoChooserTask()
        AddHandler photoChooserTask.Completed, AddressOf photoChooserTask_Completed
    End Sub
    Dim photoChooserTask As PhotoChooserTask
    Private Sub photoChooserTask_Completed(sender As Object, e As PhotoResult)
        Dim bmp As System.Windows.Media.Imaging.BitmapImage = New System.Windows.Media.Imaging.BitmapImage()
        bmp.SetSource(e.ChosenPhoto)
        Image1.Source = bmp
        Dim originalFilename = Path.GetFileName(e.OriginalFileName)
        SaveImage(e.ChosenPhoto, originalFilename, 0, 100)

    End Sub
    Public Shared Sub SaveImage(ByVal imageStream As Stream, ByVal fileName As String, ByVal orientation As Integer, ByVal quality As Integer)
        Using isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()
            If isolatedStorage.FileExists("NewPics\fileName") Then
                isolatedStorage.DeleteFile("NewPics\fileName")
            End If

            If Not isolatedStorage.DirectoryExists("NewPics") Then
                isolatedStorage.CreateDirectory("NewPics")
            End If


            'isolatedStorage.CreateDirectory("NewPics")
            'Dim fileStream As New IsolatedStorageFileStream("fileName", FileMode.Create, isolatedStorage)
            Dim fileStream = isolatedStorage.CreateFile("NewPics\" + fileName)
            Dim bitmap = New BitmapImage()
            bitmap.SetSource(imageStream)

            Dim wb = New WriteableBitmap(bitmap)
            wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, orientation, quality)
            fileStream.Close()
        End Using
    End Sub
    Private Sub Button1_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Try
            photoChooserTask.Show()

        Catch ex As System.InvalidOperationException

            MessageBox.Show("An error occurred.")
        End Try
    End Sub
End Class

Can anyone say me where I am making mistake?

Was it helpful?

Solution

The code is perfect, the problem is that silverlight uses "isolated storage" for storing files, which is, as the name implies, a completely isolated storage. A file or directory created by your application will be accessible only from your application.

I think the emulator is storing the isolated storage files only in memory, since it doesn't have to keep them after a restart. If you want to easily see inside your application's isolated storage you could use a tool like Wp7 Explorer: http://wp7explorer.codeplex.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top