c# - saveFileDialog generates 2 file instead 1? -
i not understand why generates 2 files instead of one: have same names, 1 (that ok) has right extension (extension
) , xxxxbytes, while other has no extension (file type is) , 0bytes.
stream my1stream; savefiledialog savefiledialog1 = new savefiledialog(); savefiledialog1.filter = "txt files (*.txt)|*.txt|all files (*.*)|*.*"; savefiledialog1.filterindex = 2; savefiledialog1.restoredirectory = true; if (savefiledialog1.showdialog() == dialogresult.ok) { if ((my1stream = savefiledialog1.openfile()) != null) { fileout = savefiledialog1.filename + extension; passwordbytes = getpasswordbytes(); my1stream.close(); aes.encryptfile(filein, fileout, passwordbytes); messagebox.show("file criptato!"); } }
the extension derived filein
(in openfiledialog) , declared in form: private string extension
:
filein = openfiledialog1.filename; extension = path.getextension(filein);
from msdn page on savefiledialog.openfile method
for security purposes, method creates new file selected name , opens read/write permissions. can cause unintentional loss of data if select existing file save to
so line
if ((my1stream = savefiledialog1.openfile()) != null)
creates file name selected , 0 bytes. code continues creating file in aes.encryptfile call tne name of fileout
you write
if (savefiledialog1.showdialog() == dialogresult.ok) { fileout = savefiledialog1.filename; passwordbytes = getpasswordbytes(); aes.encryptfile(filein, fileout, passwordbytes); messagebox.show("file criptato!"); }
Comments
Post a Comment