change filename on upload i table and uploads folder?

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
MichaelFiil
User
Posts: 10

change filename on upload i table and uploads folder?

Post by MichaelFiil »

I need help to code a function which renames an uploaded imagefile in the database but also in the uploads folder of asp.netmaker

We uploads 10 Photos on each car in the database, but som of the images have long names or include big letters.

Tablename is BILDATA
foto1, foto2, foto3...foto10 are the fields in table which hold the filenames in the uploads folder

I would like to generate a filename combined of [recordnumber_in_table]+foto1, [recordnumber_in_table]+foto2 ect.

Can any body help me, i have choosen C# as language

Thanks in advance

Michael fiil from Denmark


MichaelFiil
User
Posts: 10

Post by MichaelFiil »

this Works for updating!

rsnew["foto1"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto1";       
rsnew["foto2"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto2";   
rsnew["foto3"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto3"; 
rsnew["foto4"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto4";  
rsnew["foto5"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto5";  
rsnew["foto6"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto6";  
rsnew["foto7"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto7";
rsnew["foto8"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto8"; 
rsnew["foto9"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto9";  
rsnew["foto10"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto10";

How to get totalnumber of records i table, when inserting?

This dos not Work
Int Rno = Rsold["bilid"];
Rno = Rno + 1;
rsnew["foto1"] = Convert.ToString(Rno).ToLower() + "foto1";


MichaelFiil
User
Posts: 10

Post by MichaelFiil »

I m getting closer but it still dont Work!
According to suggestion in other post from Vincent i am trying this:

var rno = ew_ExecuteScalar("SELECT MAX(ID) FROM bildata");   
var rnoo = rno + 1;
rsnew["foto1"] = Convert.ToString(rnoo).ToLower() + "foto1";  

I need to get the max(id) from table to use in my filename.

But i am getting compiling error:
CS0019: Operator '+' can't be used with operands of type 'object' or 'int'


vincenthung
User
Posts: 88

Post by vincenthung »

You need to convert the "rno" to integer before add.

For example:
var rnoo = Convert.ToInt32(rno) + 1;


MichaelFiil
User
Posts: 10

Post by MichaelFiil »

Thank you Vincent - Again You solved my problem :-)

If i thoose Visual Basic as Language, would I then be able to write rno = rno + 1 as it is possible in VB?

Another thing:
By updating, i only want to change the filename, if rsnew is different from rsold. I thougt i could do i the following way:

if (rsold["foto1"].Equals(rsnew["foto1"])) 
{        
}
else
{
  rsnew["foto1"] = Convert.ToString(rsold["bilid"]).ToLower() + "foto1";  
}  

same for foto2 to foto10
no errors but if foto2 to foto10 are empty and only foto 1 are changed, foto2 to 10 still becomes recordnumber+foto2 to recordnumber+foto10 even
if no images are uploaded for foto2 to foto10??

Thanks in advantage


vincenthung
User
Posts: 88

Post by vincenthung »

You need to check the new filename is empty or not in your checking. Because when you do not upload the file, the filename field will be return null.

For example
if (ew_Empty(rsnew["foto1"]) || rsold["foto1"].Equals(rsnew["foto1"])) {
// Do nothing.
}


MichaelFiil
User
Posts: 10

Post by MichaelFiil »

Hi vincenthung and Thank You for your help.
Everything is working now :-)


Post Reply