Buen día tengan ustedes.
I have the following problem, I use Visual Studio 2013, I have created a system where the basic operations are done (search, delete, enter), linked to a database created in SQL SERVER 2008.
The problem is when I tried to enter a new record with a photo, it tells me the following:
Acceso denegado a la ruta de acceso 'C:\Users\Mi-Pc\Documents\Visual Studio 2013\EDICION CON BUNIFU\SISTEMA\SISTEMA \bin'.
The code that I use where I get the part of the error is the following:
private void buniVista_Click(object sender, EventArgs e)
{
if (txtnumero.Text == "")
{
MessageBox.Show("Digite Numero del modelo para Continuar","SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtnumero.Focus();
}
else if (txtdescripcion.Text == "")
{
MessageBox.Show("Digite la descripcion para Continuar", " SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtdescripcion.Focus();
}
else if (dtpfecha.Text == "")
{
MessageBox.Show("Digite fecha para Continuar", " SISTEMA ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
dtpfecha.Focus();
}
else if (txtTalla.Text == "SELECCIONE TALLA")
{
MessageBox.Show("Seleccione talla para Continuar", " SISTEMA ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtTalla.Focus();
}
else if (txtexaminar.Text == "")
{
MessageBox.Show("Cargue una fotografia para Continuar", " SISTEMA ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
btnexaminar.Focus();
}
else
{
FileStream stream = new FileStream(txtexaminar.Text, FileMode.Open, FileAccess.Read);
//Se inicailiza un flujo de archivo con la imagen seleccionada desde el disco.
BinaryReader br = new BinaryReader(stream);
FileInfo fi = new FileInfo(txtexaminar.Text);
//Se inicializa un arreglo de Bytes del tamaño de la imagen
byte[] binData = new byte[stream.Length];
//Se almacena en el arreglo de bytes la informacion que se obtiene del flujo de archivos(foto)
//Lee el bloque de bytes del flujo y escribe los datos en un búfer dado.
stream.Read(binData, 0, Convert.ToInt32(stream.Length));
////Se muetra la imagen obtenida desde el flujo de datos
picfotografia.Image = Image.FromStream(stream);
VistaModelo f2 = new VistaModelo();
this.Hide();
f2.Show();
f2.lblnumero.Text = txtnumero.Text.ToString();
f2.lbldescripcion.Text = txtdescripcion.Text.ToString();
f2.lblfecha.Text = dtpfecha.Text.ToString();
f2.lbltalla.Text = txtTalla.Text.ToString();
f2.txtexaminar2.Text = txtexaminar.Text.ToString();
f2.picfoto.Image = Image.FromStream(stream);
}
}
The error is specifically in this part:
FileStream stream = new FileStream(txtexaminar.Text, FileMode.Open,FileAccess.Read);