FileStream File Directory and Extension

0

How to specify the file creation directory and its extension?

byte[] vetorImagem = (byte[])cmdSelect.ExecuteScalar();
string strNomeArquivo = Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs = new FileStream(strNomeArquivo, FileMode.CreateNew, FileAccess.Write);
fs.Write(vetorImagem, 0, vetorImagem.Length);
fs.Flush();
fs.Close();
pbDefault.Visible = false;
pbUsuario.Image = Image.FromFile(strNomeArquivo);
    
asked by anonymous 25.06.2016 / 22:57

1 answer

2

Actually what you pass as the first parameter in the FileStream constructor % is not the file name but the address path of the file.

Your address should contain the path, name, and file extension in a single string . So after getting the filename you should concatenate the rest of the information to have the full address:

string strNomeArquivo = Convert.ToString(DateTime.Now.ToFileTime()),
localizacaoArquivo = "c:/",
extensaoArquivo = ".png",
enderecoArquivo = localizacaoArquivo + strNomeArquivo + extensaoArquivo;
FileStream fs = new FileStream(enderecoArquivo, FileMode.CreateNew, FileAccess.Write);
...

Note that if you want the path to some standard Windows folder, you can obtain them using the Enum from special system folders . For the My Pictures folder of the user, for example:

string localizacaoArquivo = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
    
26.06.2016 / 04:57