SetStorageItems() private method

private SetStorageItems ( [ value ) : void
value [
return void
Example #1
0
        async void CopyButton_Click(object sender, RoutedEventArgs e)
        {
            OutputText.Text = "Storage Items: ";
            var filePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.List,
                FileTypeFilter = { "*" }
            };

            var storageItems = await filePicker.PickMultipleFilesAsync();
            if (storageItems.Count > 0)
            {
                OutputText.Text += storageItems.Count + " file(s) are copied into clipboard";
                var dataPackage = new DataPackage();
                dataPackage.SetStorageItems(storageItems);

                // Request a copy operation from targets that support different file operations, like File Explorer
                dataPackage.RequestedOperation = DataPackageOperation.Copy;
                try
                {
                    Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage);
                }
                catch (Exception ex)
                {
                    // Copying data to Clipboard can potentially fail - for example, if another application is holding Clipboard open
                    rootPage.NotifyUser("Error copying content to Clipboard: " + ex.Message + ". Try again", NotifyType.ErrorMessage);
                }
            }
            else
            {
                OutputText.Text += "No file was selected.";
            }
        }
        private async Task ShareFileAsync(DashboardViewModel vm, DataPackage dataPackage, DataPackagePropertySet propertySet)
        {
            var cleanFileName = vm.SelectedItem.ImagePath.Replace(@"../Images/", "");

            var packageLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var imagesFolder = await packageLocation.GetFolderAsync("Images");
            var imageToShare = await imagesFolder.GetFileAsync(cleanFileName);

            dataPackage.SetStorageItems(new List<IStorageItem>{imageToShare});

            var imageStreamRef = RandomAccessStreamReference.CreateFromFile(imageToShare);
            propertySet.Thumbnail = imageStreamRef;

        }
Example #3
0
        private async void MainPage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            var GetFiles = args.Request.GetDeferral();
            try
            {
                var name = String.Format("{0}_{1:yyyy-MM-dd_HH-mm-ss}.jpg", "MyApp", DateTime.Now);
                StorageFolder tempFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync("MidTermTemp", CreationCollisionOption.ReplaceExisting);
                StorageFile saveItem = await tempFolder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);
                byte[] pixels;
                using (Stream pixelStream = srcWriteAbleBitmap.PixelBuffer.AsStream())
                {
                    pixels = new byte[pixelStream.Length];
                    pixelStream.Read(pixels, 0, pixels.Length);
                    for (int i = 0; i < pixels.Length; i += 4)
                    {
                        byte temp = pixels[i];
                        pixels[i] = pixels[i + 2];
                        pixels[i + 2] = temp;
                    }
                }
                using (IRandomAccessStream fileStream = await saveItem.OpenAsync(FileAccessMode.ReadWrite))
                {
                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, fileStream);
                    encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight,
                        (uint)srcWriteAbleBitmap.PixelWidth, (uint)srcWriteAbleBitmap.PixelHeight, 96, 96, pixels);
                    await encoder.FlushAsync();
                    using (var outputStream = fileStream.GetOutputStreamAt(0))
                    {
                        await outputStream.FlushAsync();
                    }
                }

                DataPackage data = new DataPackage();
                data.Properties.Title = "共享图片";
                data.Properties.Description = "分享一些内容。";
                List<IStorageItem> files = new List<IStorageItem>();
                files.Add(saveItem);
                data.SetStorageItems(files);
                args.Request.Data = data;
            }
            finally
            {
                GetFiles.Complete();
            }
        }
		private static void FillPackage(StorageFile[] files, DataPackage package, object subShareItem)
		{
			if (subShareItem != null)
			{
				switch (subShareItem.GetType().Name)
				{
					case nameof(TextShareItem):
						{
							package.SetText((subShareItem as TextShareItem).Text);
						}
						break;
					case nameof(ApplicationLinkShareItem):
						{
							var sitm = subShareItem as ApplicationLinkShareItem;
							package.SetApplicationLink(sitm.ApplicationLink);
						}
						break;

					case nameof(DelayRenderedImageShareItem):
						{
							var sitm = subShareItem as DelayRenderedImageShareItem;
							package.SetBitmap(RandomAccessStreamReference.CreateFromStream(sitm.SelectedImage.GetRandowmAccessStream()));
						}
						break;

					case nameof(FilesShareItem):
						{
							StorageFile[] resultArray = files;
							package.SetStorageItems(resultArray);
						}
						break;
					case nameof(HtmlShareItem):
						{
							var sitm = subShareItem as HtmlShareItem;

							var fmt = HtmlFormatHelper.CreateHtmlFormat(sitm.HtmlFragment);
							package.SetHtmlFormat(fmt);
							package.SetText(sitm.HtmlFragment);

						}
						break;
					case nameof(WebLinkShareItem):
						{
							var sitm = subShareItem as WebLinkShareItem;
							package.SetWebLink(sitm.WebLink);
							package.SetText(sitm.WebLink?.ToString());

						}
						break;

					default:
						break;
				}

			}
		}
        public override string CopyFiles(IList<FileInfoM> files)
        {
            string errorMessage = string.Empty;

            if (files.Any(p => p.StorageFile == null) || files.Any(p => (p.StorageFile is StorageFile) == false))
            {
                errorMessage = "Have no StorageFiles";
                return errorMessage;
            }

            var dataPackage = new DataPackage();
            var storageFiles = (from kkk in files
                select kkk.StorageFile).Cast<StorageFile>().ToList();
            dataPackage.SetStorageItems(storageFiles, true);
            dataPackage.RequestedOperation = DataPackageOperation.Copy;
            try
            {
                Clipboard.SetContent(dataPackage);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            return errorMessage;
        }
        public override string CopyFile(FileInfoM file)
        {
            string errorMessage = string.Empty;

            if (file.StorageFile == null || (file.StorageFile is StorageFile) == false)
            {
                errorMessage = "Have no StorageFile";
                return errorMessage;
            }

            var dataPackage = new DataPackage();
            dataPackage.SetStorageItems(new List<StorageFile> {(StorageFile) file.StorageFile}, true);
            dataPackage.RequestedOperation = DataPackageOperation.Copy;
            try
            {
                Clipboard.SetContent(dataPackage);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }
            return errorMessage;
        }