1
I’m trying to convert a received file into FileUpload
(ASP.NET tool) for a array of bytes and then the array for a string.
But when trying to use the Encoding
Visual Studio accuses an error saying that this class only accepts one string to convert into array of bytes.
Follows the code:
if (FileUploadControl.HasFile)
{
try
{
if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
{
if (FileUploadControl.PostedFile.ContentLength < 102400)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] arrayImg = encoding.GetBytes(FileUploadControl.PostedFile);
String img64Produto = Convert.ToBase64String(arrayImg);
}
else
//StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";
ClientScript.RegisterClientScriptBlock(Page.GetType(), "msgErroLogin", "alert('O arquivo deve ser menor que 100KB!');", true);
}
else
//StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
ClientScript.RegisterClientScriptBlock(Page.GetType(), "msgErroLogin", "alert('Apenas .jpeg são suportados!');", true);
}
catch (Exception ex)
{
//StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
String msg = "O arquivo não pode ser carregado" + ex.Message;
ClientScript.RegisterClientScriptBlock(Page.GetType(), "msgErroLogin", "alert('O arquivo não pode ser carregado.');", true);
}
}
I used Fileuploadcontrol.Filebytes and it worked thanks!
– Gabriel Souza