public static ContentItem[] ProvideContentFromClipboard(int ContentNumber, string ContentFolder) { List <ContentItem> content_list = new List <ContentItem>(); if (Clipboard.ContainsImage() == true) { System.Windows.Forms.IDataObject clipboardData = System.Windows.Forms.Clipboard.GetDataObject(); if (clipboardData == null) { return(null); } if (clipboardData.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) == false) { return(null); } System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)clipboardData.GetData(System.Windows.Forms.DataFormats.Bitmap); //string file_name = ContentFolder + ContentNumber.ToString().PadLeft(3, '0') + ".png"; string file_name = ContentFolder + ContentNumber.ToString().PadLeft(3, '0') + ".rip"; bitmap.Save(file_name, System.Drawing.Imaging.ImageFormat.Png); content_list.Add(new ContentItem(file_name)); return(content_list.ToArray()); } if (Clipboard.ContainsText()) { string clipboard_text = Clipboard.GetText().Trim(); if (Globals.IsValidUri(clipboard_text)) { string uri_str = clipboard_text; Uri uri = new Uri(uri_str); try { string file_name = System.IO.Path.GetFileName(uri.LocalPath); string file_ext = System.IO.Path.GetExtension(uri.LocalPath).Trim().ToLower(); string ext = ""; switch (file_ext) { case ".mp3": case ".wav": ext = ".ria"; break; case ".bmp": case ".png": case ".jpg": ext = ".rip"; break; case ".txt": ext = ".rit"; break; } string downloaded_file_name = ContentFolder + ContentNumber.ToString().PadLeft(3, '0') + ext; using (WebClient wc = new WebClient()) { //wc.DownloadProgressChanged += wc_DownloadProgressChanged; wc.DownloadFile(uri, downloaded_file_name); //content_list.Add(new ContentItem(ContentNumber, downloaded_file_name)); content_list.Add(new ContentItem(downloaded_file_name)); } } catch (Exception ex) { MessageBox.Show("Unable to follow URL.\n" + ex.Message); return(content_list.ToArray()); } } else { string text = Clipboard.GetText(); //string file_name = ContentFolder + ContentNumber.ToString().PadLeft(3, '0') + ".txt"; string file_name = ContentFolder + ContentNumber.ToString().PadLeft(3, '0') + ".rit"; File.WriteAllText(file_name, text); //content_list.Add(new ContentItem(ContentNumber, file_name)); content_list.Add(new ContentItem(file_name)); } return(content_list.ToArray()); } if (Clipboard.ContainsAudio()) { // Not implemented return(content_list.ToArray()); } if (Clipboard.ContainsFileDropList()) { StringCollection files = Clipboard.GetFileDropList(); for (int i = 0; i < files.Count; i++) { FileInfo fi = new FileInfo(files[i]); content_list.Add(new ContentItem(ContentNumber, ContentFolder, files[i])); } } return(content_list.ToArray()); }