En iyi yanıtlayıcılar
FileUpload aynı dosya varsa ismini değiştrisin bunu nasıl yapabilirim ?

Soru
-
Yanıtlar
-
int Urun_ID = 123;//Urun_ID
string newFileNAME= DateTime.Now.ToString().Replace(" ", "").Replace(".", "").Replace(":", "") + DateTime.Now.Millisecond.ToString() + Urun_ID.ToString();
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(MapPath("~/uploadFolder/" + newFileName));
}- Yanıt Olarak İşaretleyen Ali Rıza İnceoğlu 5 Ekim 2012 Cuma 09:30
-
File.Exists methodu size dosyanın var olup olmadığını T/F olarak döndürür. Bunu kullanarak rename yapabilirsiniz
e-mail: onay[nokta]yalciner[at]hotmail[nokta]com
- Yanıt Olarak Öneren Ali Rıza İnceoğlu 1 Ekim 2012 Pazartesi 13:15
- Yanıt Olarak İşaretleyen Ali Rıza İnceoğlu 5 Ekim 2012 Cuma 09:30
-
Dostum aynı sorun bendede vardı ben sorunumu bu sekilde halletim Guid ile örnek kod aşağıdadır :)
string a = Guid.NewGuid().ToString();
string degistir = fileResimler.PostedFile.FileName.Replace(fileResimler.PostedFile.FileName, a + ".jpg");
//Buradada Resmi Elde Ettiğimiz Adıyla İmages Dosyasına Kaydettirdik...
file.SaveAs(Server.MapPath("CarImages/" + degistir));//Db Kaydetme Kodu
con = baglan.baglan();
SqlCommand cmd2 = new SqlCommand("Insert into EvResimler(ResimAdi) values('" + degistir + "')", con);
cmd2.ExecuteNonQuery();Bu senin sorununu %90 çözecektir.
www.garipadamlar.com - Asp.Net'te Türkçe Kaynağınız
- Düzenleyen Ömer Faruk Özkan 1 Ekim 2012 Pazartesi 13:34
- Yanıt Olarak Öneren BKRHBK 1 Ekim 2012 Pazartesi 14:02
- Yanıt Olarak İşaretleyen Ali Rıza İnceoğlu 5 Ekim 2012 Cuma 09:30
Tüm Yanıtlar
-
int Urun_ID = 123;//Urun_ID
string newFileNAME= DateTime.Now.ToString().Replace(" ", "").Replace(".", "").Replace(":", "") + DateTime.Now.Millisecond.ToString() + Urun_ID.ToString();
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(MapPath("~/uploadFolder/" + newFileName));
}- Yanıt Olarak İşaretleyen Ali Rıza İnceoğlu 5 Ekim 2012 Cuma 09:30
-
-
birdeyazdığın kodu biraz açablirimisn pek anlamadım
- Yanıt Olarak Öneren Ömer Faruk Özkan 1 Ekim 2012 Pazartesi 13:34
- Yanıt Önerisini Geri Alan Ömer Faruk Özkan 1 Ekim 2012 Pazartesi 13:34
-
File.Exists methodu size dosyanın var olup olmadığını T/F olarak döndürür. Bunu kullanarak rename yapabilirsiniz
e-mail: onay[nokta]yalciner[at]hotmail[nokta]com
- Yanıt Olarak Öneren Ali Rıza İnceoğlu 1 Ekim 2012 Pazartesi 13:15
- Yanıt Olarak İşaretleyen Ali Rıza İnceoğlu 5 Ekim 2012 Cuma 09:30
-
-
Dostum aynı sorun bendede vardı ben sorunumu bu sekilde halletim Guid ile örnek kod aşağıdadır :)
string a = Guid.NewGuid().ToString();
string degistir = fileResimler.PostedFile.FileName.Replace(fileResimler.PostedFile.FileName, a + ".jpg");
//Buradada Resmi Elde Ettiğimiz Adıyla İmages Dosyasına Kaydettirdik...
file.SaveAs(Server.MapPath("CarImages/" + degistir));//Db Kaydetme Kodu
con = baglan.baglan();
SqlCommand cmd2 = new SqlCommand("Insert into EvResimler(ResimAdi) values('" + degistir + "')", con);
cmd2.ExecuteNonQuery();Bu senin sorununu %90 çözecektir.
www.garipadamlar.com - Asp.Net'te Türkçe Kaynağınız
- Düzenleyen Ömer Faruk Özkan 1 Ekim 2012 Pazartesi 13:34
- Yanıt Olarak Öneren BKRHBK 1 Ekim 2012 Pazartesi 14:02
- Yanıt Olarak İşaretleyen Ali Rıza İnceoğlu 5 Ekim 2012 Cuma 09:30
-
void
SaveFile(HttpPostedFilefile)
{
try
{
// Specify the path to save the uploaded file to.
// Get the name of the file to upload.
stringfileName = fu.FileName;
// Create the path and file name to check for duplicates.
stringpathToCheck = savePath + fileName;
// Create a temporary file name to use for checking duplicates.
stringtempfileName = "";
// Check to see if a file already exists with the
// same name as the file to upload.
if(System.IO.File.Exists(pathToCheck))
{
intcounter = 2;
while(System.IO.File.Exists(pathToCheck))
{
// if a file with this name already exists,
// prefix the filename with a number.
tempfileName = counter.ToString() + fileName;
pathToCheck = savePath + tempfileName;
counter++;
}
fileName = tempfileName;
// Notify the user that the file name was changed.
lbl.Text =
"Aynı isimde bir dosya mevcut dosya ismi değiştirilerek eklendi";
}
else
{
// Notify the user that the file was saved successfully.
lbl.Text =
"Yükleme işlemi Tamamlandı";
}
// Append the name of the file to upload to the path.
savePath += fileName;
FileInfofi = newFileInfo(savePath);
booluygun = false;
string[] str = { ".jpg", ".jpeg", ".png", ".gif"};
foreach(strings instr)
{
if(fi.Extension.ToLower() == s)
{
uygun =
true;
}
}
if(uygun == false)
{
lbl.Text =
"dosya uzantısı jpg, jpeg, png, veya gif olmalıdır";
}
else
{
Streamst = fu.FileContent;
ImageBoyutimg = newImageBoyut();
System.Drawing.
Imageimage = System.Drawing.Image.FromStream(st);
if(image.Width > 800)
{
img.yw = 800;
Bitmapbmp = img.Boyutla(image);
img.saveJpeg(savePath, bmp, 85);
bmp.Dispose();
}
else
{
Bitmapbmp = (Bitmap)image;
img.saveJpeg(savePath, bmp, 85);
}
Bind();
DataList1.DataBind();
fu.Dispose();
image.Dispose();
st.Dispose();
st.Close();
}
}
catch(Exceptionex)
{
Response.Write(ex.Message);
}
// Call the SaveAs method to save the uploaded
// file to the specified directory.
}
- Yanıt Olarak Öneren Ali Karakaya25 2 Ekim 2012 Salı 19:01