-1
In my WEB FOLDER I have the file aspx.cs
and the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using WebApplication1.App_Code;
namespace WebApplication1.bibliotecario
{
public partial class adicionar_livros : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\samue\source\repos\WebApplication1\WebApplication1\App_Data\gerenciamentoBiblioteca.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
con.Open();
}
protected void b1_Click(object sender, EventArgs e)
{
string books_image_name = Class1.GetRandomPassword(10);
string path = "";
f1.SaveAs(Request.PhysicalApplicationPath + "/bibliotecario/imagens_livros/" + f1.FileName.ToString());
path = "imagens_livros/"+f1.FileName.ToString();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into livros values('"+ titulolivros.Text +"','"+ path.ToString() + "','"+ nomeautor.Text + "','" + isbn.Text + "','" + qtd.Text + "')";
cmd.ExecuteNonQuery();
msg.Style.Add("display", "block");
}
}
}
And I have a class .cs
calling for Class1
inside an Asp.net folder, App_code folder. But every time I call Class1
she is not recognized, there is no option to put it in my code, as I do to have access to it?
This is the class Class1.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
public static string GetRandomPassword(int length)
{
char[] chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
string password = string.Empty;
Random random = new Random();
for (int i = 0; i < length; i++)
{
int x = random.Next(1, chars.Length);
//For avoiding Repetation of Characters
if (!password.Contains(chars.GetValue(x).ToString()))
password += chars.GetValue(x);
else
i=i-1;
}
return password;
}
}
lacked the
using WebApplication1.App_Code
. But without seeing the classClass1.cs
(bad name), there is no way to guess if she is with the correct namespace and nor if you can access the method without first instantiating it– Leandro Angelo
And include the question fact code, avoid presenting your problem through screenshots
– Leandro Angelo
Good afternoon Leandro, I edited the question and I put the code at disposal, referring to class I’ll leave it down here if you can help me
– SamuelAndrechuc