When i selected any folder in
FolderDialogBrowser
i got error about access denied for folder. That's for everything folders, documents, my computer, desktop etc, really every folder. I was read about user access for folders (but every folder on disk?), and run as administrator, but it don't help me. If i send me program to friend, they will have too play with folders access to select path? I'm logged on admin account and i have all permissions, but my program no.
/*
* Created by SharpDevelop.
* User: Tomek
* Date: 2019-04-05
* Time: 04:26
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Xml.Linq;
namespace meta_generator
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
OpenFileDialog files = new OpenFileDialog();
FolderBrowserDialog metaOutput = new FolderBrowserDialog();
string metapath;
void Button1Click(object sender, EventArgs e)
{
files.Filter = "Wszystkie pliki (*.*)|*.*";
files.Multiselect = true;
if (files.ShowDialog() == DialogResult.OK)
{
foreach (String file in files.FileNames)
{
textBox1.Text = textBox1.Text + ";" + file;
}
}
}
void Button2Click(object sender, EventArgs e)
{
metaOutput.Description = "Wybierz folder gdzie zostanie wygenerowany plik meta.xml";
metaOutput.RootFolder = Environment.SpecialFolder.MyDocuments;
if (metaOutput.ShowDialog() == DialogResult.OK)
{
metapath = metaOutput.SelectedPath;
textBox2.Text = metapath;
}
}
void Button3Click(object sender, EventArgs e)
{
if (textBox1.Text.Length > 0 && textBox2.Text.Length > 0)
{
XDocument meta = new XDocument(new XElement("meta"));
foreach (String file in files.FileNames)
{
XElement childFileTag = new XElement("file");
XAttribute sourcepath = new XAttribute("src", file);
childFileTag.Add(sourcepath);
meta.Root.Add(childFileTag);
}
if (checkBox1.Checked)
meta.Root.Add(new XElement("oop", "true"));
meta.Save(metapath);
}
}
}
}
The issue is your use of
meta.Save(metapath);
metapath is a folder (directory) name (like c:\temp\, not a filename (like c:\temp\bob.xml).
When saving a file, you need to save to a complete path (including filename). An example would be:
meta.Save(Path.Combine(metapath, "bob.xml"));
Alternatively, don't use FolderBrowserDialog - instead use SaveFileDialog to allow the user to choose their own filename.
Related
I am now developing Android Application and the Windows Form.
In the previous, the users need to plug in with USB, copy the file and paste into android folder but it would be troublesome and takes time to do.
How can I transfer the file directly from the PC to android Folder (Internal Storage/ downloads) ?
I tried with FolderBrowserDialog to browse and copy into android but "OK" button is disabled when I point the location. enter image description here
Should I write it in Windows Form backend or Xamarin Forms backend side in order to direct transfer into the Android App?
I cannot use Web API as cannot use the internet connection.
FolderBrowserDialog dialog = new FolderBrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
txtCopy.Text = dialog.SelectedPath;
}
string copyFileName = Path.Combine(txtCopy.Text, originalFile); //originalFile->FileName (testing.jpg)
File.Copy(txtFile1.Text, copyFileName, true);
Direct file transfer from Windows Form and Xamarin Forms by clicking button
I too had issues with copying to/from Android with Xamarin. Originally directed to use ADB.exe (Android Debug Bridge), but that had too many security holes / issues and was restricted from using that. Could not use generic 3rd party for other reasons and had to write my own Android / Xamarin file transfer library (works great). One thing I found in MY research was what was the naming convention for paths did not always match what you think it might / should. For example, your "Internal shared storage" wasn't really that when I connected.
"DT50\Internal shared storage\Download"
it was just
"Internal Storage\Download".
Did not have a leading \ character and it worked. Writing to other directories, you need to prompt/grant permission on the Xamarin side to look at SOME possible other working folder directories, but that might be something for you at another time.
Based on your code, I made a Windows Form project to complete the copy.
You could refer to the following code:
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
textBox1.Text = dialog.SelectedPath;
}
}
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.ShowDialog();
textBox2.Text = dialog.SelectedPath;
}
private void button3_Click(object sender, EventArgs e)
{
DirectoryInfo thefolder = new DirectoryInfo(textBox1.Text);
foreach (FileInfo nextfile in thefolder.GetFiles())
{
try
{
string filename = nextfile.Name;
string filefullname = nextfile.FullName;
string mudi = textBox2.Text + "\\" + filename;
if (File.Exists(mudi))
{
//File.Delete(mudi);
}
else
{
File.Copy(filefullname, mudi);
MessageBox.Show("Successful");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
}
Now I got it. I have to download MediaDevices framework in NuGet Package Manager to download/ transfer the file from Android device to PC.
I can transfer the file from Android to PC.
But the thing is I cannot transfer/ Upload the file from PC to Android (when using PCToPDA()). When I run the program, the error Director "DT50\Internal shared storage\Download" not found appear even though the directory path is correct.
Any idea why is that happening?
Updated One
The problem has been solved. Instead of writing "DT50\Internal shared storage\Download", I have to remove DT50 and just "\Internal shared storage\Download". Commented the wrong one and Updated the correct the source code below.
string originalFile;
private void BtnBrowse_Click(object sender, EventArgs e)
{
Browse(); //Get the files from Android Folder
}
private void Browse()
{
try
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtFile1.Text = openFileDialog1.FileName;
string fileName = Path.GetDirectoryName(openFileDialog1.FileName);
originalFile = Path.GetFileName(openFileDialog1.FileName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Browse-ERR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void BtnCopy_Click(object sender, EventArgs e)
{
PDAToPC(); //Android to PC
//PCToPDA(); //PC to Android
}
private void PDAToPC()
{
try
{
string DeviceNameAsSeenInMyComputer = "DT50";
var devices = MediaDevice.GetDevices();
using (var device = devices.Where(d => d.FriendlyName == DeviceNameAsSeenInMyComputer || d.Description == DeviceNameAsSeenInMyComputer).First())
{
device.Connect();
var photoDir = device.GetDirectoryInfo(#"\Internal shared storage\Download");
var files = photoDir.EnumerateFiles("*.*", SearchOption.TopDirectoryOnly);
foreach (var file in files)
{
string destinationFileName = $#"D:\KhineThein\Testing\TransferTesting\photo\{file.Name}";
if (!File.Exists(destinationFileName))
{
using (FileStream fs = new FileStream(destinationFileName, FileMode.Create, System.IO.FileAccess.Write))
{
device.DownloadFile(file.FullName, fs);
}
}
}
device.Disconnect();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "PDAToPC-ERR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void PCToPDA()
{
try
{
string DeviceNameAsSeenInMyComputer = "DT50";
string tempFileName = "CaptureImport.txt";
var devices = MediaDevice.GetDevices();
using (var device = devices.Where(d => d.FriendlyName == DeviceNameAsSeenInMyComputer || d.Description == DeviceNameAsSeenInMyComputer).First())
{
device.Connect();
var photoDir = device.GetDirectoryInfo(#"\Internal shared storage\Download");
var files = photoDir.EnumerateFiles("*.*", SearchOption.TopDirectoryOnly);
foreach (var file in files)
{
string originalFileName = $#"D:\KhineThein\Testing\TransferTesting\photo\{tempFileName}";
//string transferToFileName = $#"{DeviceNameAsSeenInMyComputer}\Internal shared storage\Download\{tempFileName}";
string transferToFileName = $#"\Internal shared storage\Download\{tempFileName}";
using (FileStream fs = new FileStream(originalFileName, FileMode.Open, System.IO.FileAccess.Read))
{
//device.DownloadFile(file.FullName, fs); //Path, Stream
device.UploadFile(fs, transferToFileName); //Stream, Path
}
}
device.Disconnect();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "PCToPDA-ERR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
I'm been wondering is there a way to save a file in specific's folder in C#?
The only method that I know is 'SaveFileDialog' but the problems is I want to save files
in folder without showing saveFilesDialog's Box.
saveFilesDialog's Box : is a box that prompts you to Click 'YES' or 'CANCEL'.
Code samples
-In form1
public Form1()
{
InitializeComponent();
}
private string Path =#"D:\Files"; //locaction i wanna stores all the files in
private int i = 0;
private button1_Click(object sender,EventArgs e)
{
i++;
SaveDialogFile save = new SaveDialogFile();
if(Save.
if (save.ShowDialog() != DialogResult.OK)return; //Prompt's Dialog will show
save.Filter = "File Text(*.txt)|*.txt";
save.InitialDirectory = Path;
save.FileName = "txt"+i.ToString();
//Goal : i want 'save.FileName' store in 'Path' without Click 'OK' or Show Prompt Dialog's box
}
Expect Result
[1]: https://i.stack.imgur.com/9JqWO.png
Anyone can help me? I kinda stuck rn :)
This is my full code it's hard to read but you'll get the point
public partial class convertMp3ToWav : Form
{
public convertMp3ToWav()
{
InitializeComponent();
}
BackgroundWorker bw;
string withoutEx;
List<string> song_lists = new List<string>();
private void button1_Click(object sender, EventArgs e)
{
bw = new BackgroundWorker();
bw.DoWork += (obj, ae) => newThread();
bw.RunWorkerAsync();
}
void newThread()
{
Thread th = new Thread
((ThreadStart)(() =>
{
file();
}));
th.SetApartmentState(ApartmentState.STA);
th.Start();
th.Join();
}
void file()
{
string path = #"D:\musics\wav";
Directory.CreateDirectory(path);
FolderBrowserDialog f = new FolderBrowserDialog();
f.ShowDialog();
string[] lists = Directory.GetFiles(f.SelectedPath, "*.*", SearchOption.AllDirectories);
foreach (string list in lists)
{
if (Path.GetExtension(list) == ".mp3")
{
string fn = Path.GetFullPath(list);
withoutEx = Path.GetFileNameWithoutExtension(fn);
song_lists.Add(fn);
Console.WriteLine(withoutEx);
SaveFileDialog save = new SaveFileDialog();
save.Filter = "Wav FIle (*.wav)|*.wav;";
//save.FileName = song_lists[0];
save.FileName = withoutEx;
save.InitialDirectory = path;
if (save.ShowDialog() == DialogResult.OK)
{
using (Mp3FileReader mp3 = new Mp3FileReader(fn))
{
using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(mp3))
{
WaveFileWriter.CreateWaveFile(save.FileName, pcm);
}
}
}
}
}
}
}
this code's work pretty well!! but i need to click 'OK' everytime!!
so is there anyway to save file without click 'OK' everytime!!
Conceptually the only thing SaveFileDialog is doing, if you merely click OK when it shows, is changing the file extension*. Use Path.ChangeExtension instead
var pathToSaveWavTo = Path.ChangeExtension(pathToMp3, "wav");
The wav will be saved alongside the mp3. If you want to save it elsewhere, use Path.Combine to build a new path e.g.
pathToSaveWavTo = Path.Combine(#"c:\temp", Path.GetFileName(pathToSaveWavTo));
*I say this because giving it a filter of *.WAV and a filename xxx without the mp3 extension will cause it to give you a filename of xxx.wav when you only click OK, thus xxx.mp3 -> xxx.wav
I'm utilizing the template from https://alanbondo.wordpress.com/2008/06/22/creating-a-system-tray-app-with-c/ for creating a system tray icon that has a right-click context menu.
I'm able to have one of the buttons launch an explorer process that opens to the root of a directory using this function
private void MyApps(object sender, EventArgs e)
{
String currentUser = Environment.UserName.ToString();
Process explorer = new Process();
explorer.StartInfo.FileName = "explorer.exe";
explorer.StartInfo.Arguments = #"C:\Users\" + currentUser + #"\desktop\MyApps";
explorer.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
explorer.Start();
}
What I would rather do is have the system tray icon button, when clicked, expand into a sub-menu that contains the contents of the desired directory, which itself contains browseable sub-folders. Imagine the (pre-Windows 8) Start menu with nested menus and applications; that is the behavior I'd like to mimic.
What I have found thus far are multiple projects people have written to create their own customized Windows Explorer shell, do actually have to go that far in order to dynamically enumerate the contents of the desired folder into the right-click context menu of a system tray icon?
I'm much more comfortable using visual studio forms for .NET applications but from what I have read, there's no way to actually 'hide' the form at launch, so for now I'm using C#
Any advice or suggestions would be appreciated. Thanks!
Edit: Here's the updated code with the suggested method for recursively populating the menu item with the contents of the specified directory. I'm now getting an error that "System.Windows.Forms.MenuItem" does not contain a definition for DropDownItems
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace MyTrayApp
{
public class SysTrayApp : Form
{
[STAThread]
public static void Main()
{
Application.Run(new SysTrayApp());
}
private NotifyIcon trayIcon;
private ContextMenu trayMenu;
public SysTrayApp()
{
trayMenu = new ContextMenu();
trayMenu.MenuItems.Add("Exit", OnExit);
trayMenu.MenuItems.Add("My Applications").Click += new EventHandler(MyApps);
trayIcon = new NotifyIcon();
trayIcon.Text = "MyTrayApp";
trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);
trayIcon.ContextMenu = trayMenu;
trayIcon.Visible = true;
}
protected override void OnLoad(EventArgs e)
{
Visible = false; // Hide form window.
ShowInTaskbar = false; // Remove from taskbar.
base.OnLoad(e);
}
private void OnExit(object sender, EventArgs e)
{
Application.Exit();
}
protected override void Dispose(bool isDisposing)
{
if (isDisposing)
{
trayIcon.Dispose();
}
base.Dispose(isDisposing);
}
private void MyApps(object sender, EventArgs e)
{
String currentUser = Environment.UserName.ToString();
string[] directories = Directory.GetDirectories(#"C:\Users\" + currentUser + #"\desktop\My Applications");
foreach (string dir in directories)
{
string[] subdir = Directory.GetDirectories(dir);
this.trayMenu.MenuItems.Add(dir);
foreach (string sub in subdir)
{
(trayMenu.MenuItems[trayMenu.MenuItems.Count - 1] as MenuItem).DropDownItems.Add(sub);
}
string[] files = Directory.GetFiles(dir);
foreach (string file in files)
{
this.trayMenu.MenuItems.Add(file);
}
}
}
}
}
This is a simple quick test i've made, using a simple ContextMenuStrip. It of course should be recursive, but just to get you on the track:
string[] directories = Directory.GetDirectories(#"D:\descargas");
foreach (string dir in directories)
{
string[] subdir = Directory.GetDirectories(dir);
this.contextMenuStrip1.Items.Add(dir);
foreach(string sub in subdir)
{
(contextMenuStrip1.Items[contextMenuStrip1.Items.Count-1] as ToolStripMenuItem).DropDownItems.Add(sub);
}
string[] files = Directory.GetFiles(dir);
foreach(string file in files)
{
this.contextMenuStrip1.Items.Add(file);
}
}
Edit
As you are using ContextMenu, and using your provided code, you should do something like this:
private void MyApps(object sender, EventArgs e)
{
String currentUser = Environment.UserName.ToString();
string[] directories = Directory.GetDirectories(#"C:\Users\" + currentUser + #"\desktop\My Applications");
foreach (string dir in directories)
{
string[] subdir = Directory.GetDirectories(dir);
MenuItem mi=new MenuItem(dir);
foreach (string sub in subdir)
{
mi.MenuItems.Add(sub);
}
string[] files = Directory.GetFiles(dir);
foreach (string file in files)
{
mi.MenuItems.Add(file);
}
this.trayMenu.MenuItems.Add(mi);
}
}
I haven't tested it, but I think this would do more or less what you want
I am totally new to C# coding - I am trying to take screen shots of webpages whose URLs are initially picked up form a notepad uploaded on the same form.
As I read through the documentation on the web_browser control in MSDN.. I did arrive at the following code - yet when I run, I only get white screens
I tried uploading a .txt with (google/yahoo URLs as test data in 2 lines)
Can someone please say what more should I take care apart from handling which should get what I want as I read in MSDN.
P.S: pls forgive if I'm terribly wrong in coding style .. as aforesaid I'm just starting my C# coding :)
Code that I tried...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MSDN_wbc_tut1
{
public partial class Form1 : Form
{
public int temp = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void FileUploadButton1_Click(object sender, EventArgs e)
{
//once a file is uploaded i want Pgm to read contents & browse them as URLS
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.CheckFileExists = true;
openFileDialog.AddExtension = true;
openFileDialog.Multiselect = true;
//Filtering for Text files alone
openFileDialog.Filter = "text files (*.txt)|*.txt";
//if file is selected we must then do our coding part to proceed hecneforth
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//my code to say pgm wat to do once upload done...
//Getting my Chosen file's name
string Fileuploaded = openFileDialog.FileName;
//Read all line opens files - reads till EOF & closes ,prevents a while condition
string[] FileuploadedContent = System.IO.File.ReadAllLines(Fileuploaded);
foreach (string s in FileuploadedContent)
{
NavigateContent(s);
}
}
}
private void NavigateContent(string lineasurl)
{
// Add an event handler that images the document after it loads.
try
{
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler
(takescreen);
webBrowser1.Navigate(new Uri(lineasurl));
//webBrowser1.Navigate(lineasurl); also works
}
catch (System.UriFormatException)
{
return;
}
}
private void takescreen(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//specifying sample values for image or screenshot size
int x = 600, y = 700;
Bitmap bitmap = new Bitmap(x, y);
webBrowser1.DrawToBitmap(bitmap, new Rectangle(0, 0, x, y));
//to give each screen a unique name - i append some no onto it
temp = temp + 1;
string TempFname = "Screenshotref" + temp.ToString() + "." + "jpg";
bitmap.Save(TempFname);
}
}
}
I am working on a .NET program that is intended to iterate through a selected directory and allow the renaming of image files after displaying the images. I feel through my code that around 98% of the program is done, but I used a while loop to wait for the pressing of a button so as to allow for the renaming of the image file. Yet, the while loop freezes the program every time the while loop is iterated.
How can I either system("pause"); like in C++ to have the while loop pause without freezing the program and creating an infinite loop or how can I have the while loop paused automatically until a button is pressed?
Here is a tidbit of the code for the loop:
paused = true;
bool X = false;
label2.Text = "please choose a file name and press next";
//while statement
while (X == false)
{
if (paused == false)
{
//Renames filename
string newFileName = filenameTextbox.Text;
//Adds filename to selected directory where user wishes to send file to
string outputFile = destinationDirectory + "\\" + intCounter + fileNameOfficial;
//Pause statement to move to next operand..
//Copies post iterated file to selected directory
File.Copy(inputFile, outputFile, true);
X = true;
}
}
The code in its entirety is below.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
namespace recursionBitches
{
public partial class fileSorter : Form
{
bool paused = true;
public fileSorter()
{
InitializeComponent();
}
private void browseFrom_Click(object sender, EventArgs e)
{
//Warning dialouge for selecting a large file.
MessageBox.Show("Warning, before selecting the origination file, it is important to note that choosing too large of a directory (for example, my documents or 'C://') more than likely will cause this program to freeze. ");
MessageBox.Show("You have been warned");
//Choose the originating dir path. This dir path is to be later sorted using recursion.
//Once the originating dir path is chosen, it is added to the label above the button.
if (fromBrowse.ShowDialog(
) == DialogResult.OK)
{
this.originationLabel.Text = fromBrowse.SelectedPath;
}
}
private void browseTo_Click(object sender, EventArgs e)
{
//Choose the send to dir path. This dir path is to later have the files that are sorted sent to it.
//Once the to dir path is chosen, it is added to the label above the button.
if (toBrowse.ShowDialog(
) == DialogResult.OK)
{
this.sendingLabel.Text = toBrowse.SelectedPath;
}
}
private void sortButton_Click(object sender, EventArgs e)
{
string fileExtension = "*" + fileExtensionTextbox.Text;
//Check from path to ensure they are set to a user defined path.
int intCounter = 1;
if (originationLabel.Text != "From")
{
//Check to path to ensure it is set to a user defined path.
if (sendingLabel.Text != "To")
{
//Recursion stuff...
string sourceDirectory = fromBrowse.SelectedPath;
string destinationDirectory = toBrowse.SelectedPath;
//Sends origination path to function ae this is a function call. its num = 8675309... I think its name is Jenny.
recursiveRecursion(sourceDirectory, destinationDirectory, fileExtension, intCounter);
}
else
{
//Message box that says it is required to
MessageBox.Show("You dun goofed");
}
}
else
{
//Yup, it's a message box.
//That was an unhelpful comment....
/Aalmost as unhelpful as this comment
// This is what happens when I program stoned.
MessageBox.Show("You dun goofed");
}
//Grabs the path of the originating directory.
//After the originating directory path is choosen, send the path to a recursion function
//which will search the folders and sort the files in the dir. path.
}
private void originationLabel_Click(object sender, EventArgs e)
{
MessageBox.Show("Silly user, I am a label. I dont even click");
}
private void sendingLabel_Click(object sender, EventArgs e)
{
MessageBox.Show("Silly user, I am a label. I dont even click");
}
//Recursion function which grabs the directory path, uses a foreach loop to iterate through the files.
//Whilst each file is iterated through, have the recursive function select the files by extension and copy
//the files to another directory chosen by the user.
private void recursiveRecursion(string sourceDirectory, string destinationDirectory, string fileExtension, int intCounter)
{
//Select files Path and stuff
string[] filenames = Directory.GetFiles(sourceDirectory, fileExtension);
//foreach (string directoryName in directoryNames)
string[] directoryNames = Directory.GetDirectories(sourceDirectory);
//dir is the file name, as in for each file name in directory do the thing in this recursion loop thingy.
foreach (string fileName in filenames)
{
try
{
if (File.Exists(fileName))
{
//Don't use recursion. It is a file
//copy files here and stuff.
intCounter++;
//For the destination file ae dir2 to work, I need to get the file name from the file path.
//Currently dir is the file path.
//Enter code here to get the file name from the file path.
//Displays on label name of the file.
this.filesortTextbox.Text = "the file being copied is " + fileName;
//Gets filename from path
string fileNameOfficial = Path.GetFileName(fileName);
//Enters text of filename into filename textbox
filenameTextbox.Text = fileNameOfficial;
//For copying purposes, adds filename to originating directory path.
string inputFile = sourceDirectory + "\\" + fileNameOfficial;
//Assigns image from the origination directory.
Image img = Image.FromFile(inputFile);
// Shows image in the image viewer...
iteratedPicturebox.Image = img;
iteratedPicturebox.Width = img.Width;
iteratedPicturebox.Height = img.Height;
//Allows the user to change file name, after changing filename allows
//user to go to next file to rename. This is awesome for files...
paused = true;
bool X = false;
label2.Text = "Please choose a file name and press next.";
//while statement
while (X == false)
{
if (paused == false)
{
//Renames filename
string newFileName = filenameTextbox.Text;
//Adds filename to selected directory where user wishes to send file to.
string outputFile = destinationDirectory + "\\" + intCounter + fileNameOfficial;
//Pause statement to move to next operand..
//Copies post iterated file to selected directory.
File.Copy(inputFile, outputFile, true);
X = true;
}
}
}
else
{
//This really has an unknown pourpose, admittably keeping here for good luck...
Console.WriteLine("{0} is not a valid file or directory.", fileName);
}
}
catch (Exception e)
{
//What process failed you ask? Good question mate.
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
//Long story short for each directory contained in the list of directories.
//Do the stuff listed in the foreach statement.
foreach (string directoryName in directoryNames)
{
try
{
if (Directory.Exists(directoryName))
{
//If this is a directory, send the thing through itself.
// MessageBox.Show("now going through the "+ directoryName + " directory");
recursiveRecursion(directoryName, destinationDirectory, fileExtension, intCounter);
this.directoryIterated.Text = "The Current Directory The Files Are being copied from is " + directoryName;
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
private void fileExtensionTextbox_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void directoryIterated_Click(object sender, EventArgs e)
{
MessageBox.Show("I am a label. I don't even click");
this.directoryIterated.Text = "You pressed me.";
}
private void kill_Click(object sender, EventArgs e)
{
Close();
}
private void filesortTextbox_Click(object sender, EventArgs e)
{
MessageBox.Show("I am a label. I don't even click.");
this.directoryIterated.Text = "You pressed me.";
}
private void iteratedPicturebox_Click(object sender, EventArgs e)
{
MessageBox.Show("I am a picture box, I don't even click.");
}
private void nextButton_Click(object sender, EventArgs e)
{
if (paused == false)
{
paused = true;
}
else
{
paused = false;
}
}
}
}
Consider using a BackgroundWorker for your processing loop. This allows you to process this on the background thread and won't freeze your main UI thread (which is what is happening)
Rather than trying to stop execution, I would display a dialog box:
Create form eg: FileRenameDialog.
Add public properties to form you can use to set From: text, etc.
Create instance of form. eg: FileRenameDialog reuseme
Whenever the user needs to make a selection, populate the text in the dialog. eg: reuseme.Source = "The current file being copied...";
Display the dialog to the user as modal eg: var dlgResult = reuseme.ShowDialog(this);
Do what you need to with the result eg: if (dlgResult == DialogResult.OK) {...do stuff with the properties of reuseme...}