15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Moving, Copying, <strong>and</strong> Deleting files ❘ 783<br />

}<br />

buttonCopyTo.Enabled = true;<br />

buttonDelete.Enabled = true;<br />

buttonMoveTo.Enabled = true;<br />

code download FilePropertiesAndMovement.sln<br />

You also need to make one change to DisplayFolderList:<br />

protected void DisplayFolderList(string folderFullName)<br />

{<br />

DirectoryInfo theFolder = new DirectoryInfo(folderFullName);<br />

if (!theFolder.Exists)<br />

{<br />

throw new DirectoryNotFoundException("Folder not found: " + folderFullName);<br />

}<br />

ClearAllFields();<br />

DisableMoveFeatures();<br />

textBoxFolder.Text = theFolder.FullName;<br />

currentFolderPath = theFolder.FullName;<br />

// list all subfolders in folder<br />

foreach(DirectoryInfo nextFolder in theFolder.GetDirectories())<br />

listBoxFolders.Items.Add(NextFolder.Name);<br />

}<br />

// list all files in folder<br />

foreach(FileInfo nextFile in theFolder.GetFiles())<br />

listBoxFiles.Items.Add(NextFile.Name);<br />

code download FilePropertiesAndMovement.sln<br />

DisableMoveFeatures is a small utility function that disables the new controls:<br />

void DisableMoveFeatures()<br />

{<br />

textBoxNewPath.Text = "";<br />

textBoxNewPath.Enabled = false;<br />

buttonCopyTo.Enabled = false;<br />

buttonDelete.Enabled = false;<br />

buttonMoveTo.Enabled = false;<br />

}<br />

You also need to add extra code to ClearAllFields() to clear the extra text box:<br />

protected void ClearAllFields()<br />

{<br />

listBoxFolders.Items.Clear();<br />

listBoxFiles.Items.Clear();<br />

textBoxFolder.Text = "";<br />

textBoxFileName.Text = "";<br />

textBoxCreationTime.Text = "";<br />

textBoxLastAccessTime.Text = "";<br />

textBoxLastWriteTime.Text = "";<br />

textBoxFileSize.Text = "";<br />

textBoxNewPath.Text = "";<br />

}<br />

The next section takes a look at reading <strong>and</strong> writing to files.<br />

code download FilePropertiesAndMovement.sln<br />

code download FilePropertiesAndMovement.sln<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!