How to check is image with same name exist in camera roll before making copy of that

HI , I am using below code to copy image to camera roll , but if image with same name already exist i want to perform some other stuff

PHFetchOptions options = new PHFetchOptions()
{
IncludeAssetSourceTypes = PHAssetSourceType.UserLibrary
};

        options.Predicate = NSPredicate.FromFormat("title = %@", NSObject.FromObject(albumName));
        PHFetchResult result = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.Album,
                                                                         PHAssetCollectionSubtype.Any,
                                                                         options);


        PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() =>
        {
            if (result.Count > 0)
            {   // assign image to existing album
                var album = result.firstObject as PHAssetCollection;
                var albumChangeRequest = PHAssetCollectionChangeRequest.ChangeRequest(album);
                var assignImageRequest = PHAssetChangeRequest.FromImage(fileUrl);
                albumChangeRequest.AddAssets(new PHObject[] { assignImageRequest.PlaceholderForCreatedAsset });
            }
            else
            {   // create new album and assign the image to the album
                var albumChangeRequest = PHAssetCollectionChangeRequest.CreateAssetCollection(albumName);
                var assignImageRequest = PHAssetChangeRequest.FromImage(fileUrl);
                albumChangeRequest.AddAssets(new PHObject[] { assignImageRequest.PlaceholderForCreatedAsset });
            }
        }, (success, error) =>
        {
            if (!success)
               //error
            else
            {
                try
                {
                   // no error
                }
                catch{}
            }
        });
Sign In or Register to comment.