Login / Register
▼
Binary Fortress
Binary Fortress Software
CheckCentral
ClipboardFusion
CloudShow
DisplayFusion
FileSeek
HashTools
LogFusion
Notepad Replacer
Online Base64 Decoder
Online Base64 Encoder
Online JSON Formatter
ShellSend
TrayStatus
VoiceBot
WallpaperFusion
Window Inspector
More Apps...
DisplayFusion
CheckCentral
CloudShow
ClipboardFusion
FileSeek
VoiceBot
WallpaperFusion
▼
Download
Download
Change Log
Download Beta
Beta Change Log
License (EULA)
▼
Features
Features
HotKeys
Macros
Triggers
Clipboard Syncing
Clipboard Manager
Languages
Free vs Pro
Purchase
Screenshots
Apps
▼
Online
Online
Recent Items
Pinned Items
▼
Help
Help Guide
FAQ
Discussions
Contact Us
Find My License
Mailing Address
Advanced Settings
Macros
Languages
Clipboard
Fusion
WARNING: You currently have Javascript disabled!
This website will not function correctly without Javascript enabled.
Title
Message
OK
Confirm
Yes
No
Save Text or Image to Disk
Return to ClipboardFusion Macros
Description
Prompts for a folder and a filename and saves the selected item (or clipboard contents) to the disk. Only works for text or images.
Language
C# (.Net)
Minimum Version
5.5.1+
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Apr 3, 2019
Date Last Modified
Apr 5, 2019
Macro Code
Copy
Select All
Toggle Line Wrapping
using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; public static class ClipboardFusionHelper { public static string ProcessText(string text) { // Get the selected item index if applicable int selectedIndex = BFS.ClipboardFusion.GetClipboardManagerSelectedIndex(); // Prompt for the folder path string folderPath = BFS.Dialog.GetUserInput("Please enter a folder path to save to:", @"%USERPROFILE%\Documents\ClipboardFusion Saved Items\"); folderPath = Environment.ExpandEnvironmentVariables(folderPath); if (!(folderPath.EndsWith(@"\"))) folderPath += @"\"; // Create the folder if needed if (!(Directory.Exists(folderPath))) Directory.CreateDirectory(folderPath); // If run by right-clicking a Clipboard Manager item, check if it's text if (BFS.ClipboardFusion.GetSelectedListItemContainsText(selectedIndex)) { // Prompt for the filename string fileName = BFS.Dialog.GetUserInput("Please enter the file name for this text:", @"File.txt"); // Check if the file exists and update the filename if needed fileName = CheckIfFileExists(folderPath, fileName); // Write the file File.WriteAllText(folderPath + fileName, BFS.ClipboardFusion.GetSelectedListText(selectedIndex)); } // If run by right-clicking a Clipboard Manager item, check if it's an image else if (BFS.ClipboardFusion.GetSelectedListItemContainsImage(selectedIndex)) { // Prompt for the filename string fileName = BFS.Dialog.GetUserInput("Please enter the file name for this image:", @"File.jpg"); // Check if the file exists and update the filename if needed fileName = CheckIfFileExists(folderPath, fileName); // Write the file BFS.ClipboardFusion.GetSelectedListImage(selectedIndex).Save(folderPath + fileName, System.Drawing.Imaging.ImageFormat.Jpeg); } // If it's not run by right-clicking a Clipboard Manager item, check if the clipboard contains text else if (Clipboard.ContainsText()) { // Prompt for the filename string fileName = BFS.Dialog.GetUserInput("Please enter the file name for this text:", @"File.txt"); // Check if the file exists and update the filename if needed fileName = CheckIfFileExists(folderPath, fileName); // Write the file File.WriteAllText(folderPath + fileName, Clipboard.GetText()); } // If it's not run by right-clicking a Clipboard Manager item, check if the clipboard contains an image else if (Clipboard.ContainsImage()) { // Prompt for the filename string fileName = BFS.Dialog.GetUserInput("Please enter the file name for this image:", @"File.jpg"); // Check if the file exists and update the filename if needed fileName = CheckIfFileExists(folderPath, fileName); // Write the file Clipboard.GetImage().Save(folderPath + fileName, System.Drawing.Imaging.ImageFormat.Jpeg); } // Exit the macro return null; } public static string CheckIfFileExists(string folderPath, string fileName) { if (File.Exists(folderPath + fileName)) { int i = 1; string extension = Path.GetExtension(folderPath + fileName); string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName); string newFileName = fileNameNoExtension + "0" + i + extension; while (File.Exists(folderPath + newFileName)) { if (i < 10) newFileName = fileNameNoExtension + "0" + i + extension; else if (i > 10) newFileName = fileNameNoExtension + i + extension; i++; } return newFileName; } else { return fileName; } } }
Copyright © 2007-2021 Binary Fortress Software
•
News
•
Discussions
•
FAQ
•
Support
•
Privacy
•
ToS
•
Get Binary Fortress Merch