FileNotFound when renaming photo WP8

30 views Asked by At

Im developing a Windows Phone 8 app that requires the camera. I take the picture and upload the pic to the server by reading the Stream in the ChosenPhoto property. Once the upload finish, I need to rename the file to match some local convention. So I pass the OriginalName property to the method but when making the renaming a FileNotFoundException is thrown.

Here is the method that renames the file:

public static void SetDocumentFlag(DocumentFlag flag, string photoName)
{
    string fileName = Path.GetFileNameWithoutExtension(photoName);
    string filenameWithFlag = null;

    if (flag == DocumentFlag.Send)
    {
        if (!photoName.StartsWith(SEND_FLAG))
        {
            filenameWithFlag = "dsend_" + fileName;
        }
        else
        {
            filenameWithFlag = fileName;
        }
    }
    else
    {
        if (!photoName.StartsWith(NOT_SEND_FLAG))
        {
            filenameWithFlag = "nsend_" + fileName;
        }
        else
        {
            filenameWithFlag = fileName;
        }
    }

    string nameReplacement = photoName.Replace(fileName, filenameWithFlag);
    File.Move(photoName, nameReplacement);// here throw the exception
    File.Delete(photoName);
}

I don't understand why the exception is thrown since the photo is being saved to the camera roll successfully. I can find the picture in the camera roll.

What am I missing?

0

There are 0 answers