I was wondering why i'm getting an empty string value when i try to retrieve a filename. To better understand what i meant. In order to get the filename from the AjaxFileUpload control, I would do this code(which is in class named CreateBrands):
What I have tried:
string filename = Path.GetFileName(e.FileName);
ConnectionClassGuitarItems.stringInstrumentFileName1 = filename;
itemFileUpload1.SaveAs(Server.MapPath("~/Images/Brands/String Instrument Items/Guitar/") + filename);
As you can see, i passed the string filename to ConnectionClassGuitarItems.stringInstrumentFileName1, which is a property in a class called ConnectionClassGuitarItems. Here is a bit of code in the ConnectionClassGuitarItems. I did not include everything in there since it is not related to the question.
public static class ConnectionClassGuitarItems
{
public static string stringInstrumentFileName1 { get; set; }
}
After that, I would go back to the class CreateBrands and I would use that property to add it in my database. Here is another piece of the code:
protected void Button1_Click(object sender, EventArgs e)
{
if (itemType1.Checked)
{
try {
string item_image1 = ConnectionClassGuitarItems.stringInstrumentFileName1;
string item_image2 = ConnectionClassGuitarItems.stringInstrumentFileName2;
ConnectionClassGuitarItems.AddStringInstrumentItems(item_image1,item_image2);
And here is where i finally add it into the database:
public static void AddStringInstrumentItems(string itemimage1, string
itemimage2)
{
MusicStoreDBEntities obj = new MusicStoreDBEntities();
instrumentItem s = new instrumentItem();
s.itemimage1 = itemimage1;
s.itemimage2 = itemimage2;
obj.instrumentItems.Add(s);
obj.SaveChanges();
}
That's basically the flow of the code. My problem is, the filename would always be empty. Kindly advise or give solution on this if i'm doing something wrong that is causing it to pass a filename that is empty.