internal void UploadFile(string fileName, Stream stream) { IPortableDeviceValues portableDeviceValues = new PortableDeviceValues() as IPortableDeviceValues; portableDeviceValues.SetStringValue(ref WPD.OBJECT_PARENT_ID, this.Id); portableDeviceValues.SetUnsignedLargeIntegerValue(ref WPD.OBJECT_SIZE, (ulong)stream.Length); portableDeviceValues.SetStringValue(ref WPD.OBJECT_ORIGINAL_FILE_NAME, fileName); portableDeviceValues.SetStringValue(ref WPD.OBJECT_NAME, fileName); // test using (PropVariantFacade now = PropVariantFacade.DateTimeToPropVariant(DateTime.Now)) { portableDeviceValues.SetValue(ref WPD.OBJECT_DATE_CREATED, ref now.Value); portableDeviceValues.SetValue(ref WPD.OBJECT_DATE_MODIFIED, ref now.Value); uint num = 0u; string text = null; this.device.deviceContent.CreateObjectWithPropertiesAndData(portableDeviceValues, out IStream wpdStream, ref num, ref text); using (StreamWrapper destinationStream = new StreamWrapper(wpdStream)) { stream.CopyTo(destinationStream); destinationStream.Flush(); } } }
private IPortableDeviceValues GetRequiredPropertiesForContentTypeFromStream(MemoryStream inputStream, string fileName, string parentObjectId) { var values = new PortableDeviceValues() as IPortableDeviceValues; var wpdObjectParentId = new _tagpropertykey { fmtid = CreateFmtidGuid(), pid = 3 }; values.SetStringValue(ref wpdObjectParentId, parentObjectId); var wpdObjectSize = new _tagpropertykey { fmtid = CreateFmtidGuid(), pid = 11 }; values.SetUnsignedLargeIntegerValue(wpdObjectSize, (ulong)inputStream.Length); var wpdObjectOriginalFileName = new _tagpropertykey { fmtid = CreateFmtidGuid(), pid = 12 }; values.SetStringValue(wpdObjectOriginalFileName, fileName); var wpdObjectName = new _tagpropertykey { fmtid = CreateFmtidGuid(), pid = 4 }; values.SetStringValue(wpdObjectName, fileName); return(values); }
private static IPortableDeviceValues GetRequiredPropertiesForContentType( string fileName, string parentFolderId, ulong contentLength) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(fileName); } if (string.IsNullOrEmpty(parentFolderId)) { throw new ArgumentNullException(nameof(parentFolderId)); } IPortableDeviceValues values = new PortableDeviceValues() as IPortableDeviceValues; values.SetStringValue(ref PortableDevicePKeys.WPD_OBJECT_PARENT_ID, parentFolderId); values.SetUnsignedLargeIntegerValue(ref PortableDevicePKeys.WPD_OBJECT_SIZE, contentLength); values.SetStringValue(ref PortableDevicePKeys.WPD_OBJECT_ORIGINAL_FILE_NAME, fileName); values.SetStringValue(ref PortableDevicePKeys.WPD_OBJECT_NAME, fileName); return(values); }
internal void UploadFile(string fileName, Stream stream) { IPortableDeviceValues portableDeviceValues = new PortableDeviceValues() as IPortableDeviceValues; portableDeviceValues.SetStringValue(ref WPD.OBJECT_PARENT_ID, this.Id); portableDeviceValues.SetUnsignedLargeIntegerValue(ref WPD.OBJECT_SIZE, (ulong)stream.Length); portableDeviceValues.SetStringValue(ref WPD.OBJECT_ORIGINAL_FILE_NAME, fileName); portableDeviceValues.SetStringValue(ref WPD.OBJECT_NAME, fileName); uint num = 0u; string text = null; this.device.deviceContent.CreateObjectWithPropertiesAndData(portableDeviceValues, out PortableDeviceApiLib.IStream wpdStream, ref num, ref text); using (StreamWrapper destinationStream = new StreamWrapper(wpdStream)) { stream.CopyTo(destinationStream); destinationStream.Flush(); } }
/// <summary> /// Sets the values of multiple properties. /// </summary> /// <param name="data">The keys and values of properties to set.</param> /// <returns>The new values of the properties. Actual values may not match requested values.</returns> public IDictionary <PropertyKey, object> SetProperties(DataFieldInfo[] data) { if (data == null || data.Length == 0) { throw new ArgumentNullException("data", "Data field array must not be null or empty."); } IPortableDeviceValues pdv = new PortableDeviceValues(); for (int i = 0; i < data.Length; i++) { PropertyKey propKey = data[i].Key; object value = data[i].Value; if (value == null) { throw new ArgumentNullException("data", String.Format("Data contains a null value at index {0}", i)); } if (value is string) { pdv.SetStringValue(ref propKey, (string)value); } else if (value is uint) { pdv.SetUnsignedIntegerValue(ref propKey, (uint)value); } else if (value is int) { pdv.SetSignedIntegerValue(ref propKey, (int)value); } else if (value is ulong) { pdv.SetUnsignedLargeIntegerValue(ref propKey, (ulong)value); } else if (value is long) { pdv.SetSignedLargeIntegerValue(ref propKey, (long)value); } else if (value is float || value is double) { pdv.SetFloatValue(ref propKey, (float)value); } else if (value is bool) { pdv.SetBoolValue(ref propKey, ((bool)value) ? 1 : 0); } else if (value is Guid) { Guid guid = (Guid)value; pdv.SetGuidValue(ref propKey, ref guid); } else if (value is byte[]) { byte[] buffer = (byte[])value; pdv.SetBufferValue(ref propKey, buffer, (uint)buffer.Length); } else { pdv.SetIUnknownValue(ref propKey, value); } } IPortableDeviceValues pdv2 = null; _iSensor.SetProperties(pdv, out pdv2); Dictionary <PropertyKey, object> results = new Dictionary <PropertyKey, object>(); if (pdv2 == null) { return(results); } uint count = 0; pdv2.GetCount(ref count); for (uint i = 0; i < count; i++) { PropertyKey propKey = new PropertyKey(); PROPVARIANT propVal = new PROPVARIANT(); try { pdv2.GetAt(i, ref propKey, out propVal); results.Add(propKey, propVal.Value); } finally { propVal.Clear(); } } return(results); }