This is continuation of previous article. In fact, there is no difference in save dialog and open file dialog. The difference if that here you can get message of replacing file. Save File dialog does not save anything, you have to save it yourself.
Below is the code for the same :
Hope this article was useful for you. Thanks for reading!
Below is the code for the same :
#----------------------------------------------------------------------------------------# #-- Function Declaration #----------------------------------------------------------------------------------------# function Save-File([string] $initialDirectory ) { [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null $OpenFileDialog = New-Object System.Windows.Forms.SaveFileDialog $OpenFileDialog.initialDirectory = $initialDirectory $OpenFileDialog.filter = "All files (*.*)| *.*" $OpenFileDialog.ShowDialog() | Out-Null return $OpenFileDialog.filename } #----------------------------------------------------------------------------------------# #Usage : #----------------------------------------------------------------------------------------# $File=Save-File "C:\temp\tips" if ( $File -ne "" ) { echo "You choose FileName: $File" } else { echo "No File was chosen" }
Hope this article was useful for you. Thanks for reading!
Thanks for the script!
ReplyDelete