/** * Delete a file. */ public void DeleteFile(PortableDeviceFile file) { try { // make sure that we are not holding on to a file. DisconnectConnect(); IPortableDeviceContent content = getContents(); var variant = new PortableDeviceApiLib.tag_inner_PROPVARIANT(); StringToPropVariant(file.Id, out variant); PortableDeviceApiLib.IPortableDevicePropVariantCollection objectIds = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; objectIds.Add(variant); content.Delete(0, objectIds, null); } catch (Exception ex) { Console.WriteLine(ex.Message); throw (ex); } Disconnect(); }
public void DeleteFile(PortableDeviceFile file) { var variant = new PortableDeviceApiLib.tag_inner_PROPVARIANT(); IPortableDeviceContent content = null; try { this._device.Content(out content); StringToPropVariant(file.Id, out variant, 2); PortableDeviceApiLib.IPortableDevicePropVariantCollection objectIds = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; objectIds.Add(variant); content.Delete(0, objectIds, null); } catch (Exception ex) { Logger.Basic.Error("Portable Device DeleteFile : " + ex.ToString(), ex); } finally { if (Marshal.IsComObject(variant)) { Marshal.ReleaseComObject(variant); } if (content != null && Marshal.IsComObject(content)) { Marshal.ReleaseComObject(content); } } }
/// <summary> /// delete the specified object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object to delete</param> public void DeleteObject(IPortableDeviceContent deviceContent, string objectId) { var objectIdCollection = (IPortableDevicePropVariantCollection) new PortableDeviceTypesLib.PortableDevicePropVariantCollectionClass(); var propVariantValue = PropVariant.StringToPropVariant(objectId); objectIdCollection.Add(ref propVariantValue); // TODO: get the results back and handle failures correctly deviceContent.Delete(PortableDeviceConstants.PORTABLE_DEVICE_DELETE_NO_RECURSION, objectIdCollection, null); }
/// <summary> /// delete the specified object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object to delete</param> public void DeleteObject(IPortableDeviceContent deviceContent, string objectId) { var objectIdCollection = (IPortableDevicePropVariantCollection)new PortableDeviceTypesLib.PortableDevicePropVariantCollectionClass(); var propVariantValue = PropVariant.StringToPropVariant(objectId); objectIdCollection.Add(ref propVariantValue); // TODO: get the results back and handle failures correctly deviceContent.Delete(PortableDeviceConstants.PORTABLE_DEVICE_DELETE_NO_RECURSION, objectIdCollection, null); }