locked
code for single fileupload ..$ RRS feed

  • Question

  • User-2030851587 posted


                        if (fuimage.HasFile)
                        {
                            Byte[] bytes = fuimage.FileBytes;
                            MemoryStream ms = new MemoryStream(bytes);
                            System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
                            string imagename = fuimage.FileName;
                            string dirpath = System.Web.HttpContext.Current.Server.MapPath("\\Photos\\Communities\\" + pout.ToString());
                            DirectoryInfo drinfo = new DirectoryInfo("" + dirpath + "");
                            if (!drinfo.Exists)
                            {
                                drinfo.Create();
                            }
                            string serverpath = dirpath + "\\" + imagename;
                            img.Save(serverpath);
                            string dbpath = "~/Photos/Communities/" + pout.ToString() + "/" + imagename;
                           // dalcommunities.UpdateImagePathByCommunity_ID(pout, dbpath);
                            dalcommunities.UpdateImagepathByCommunity_ID(pout, dbpath);

                        }


    Wednesday, November 25, 2009 4:16 AM

All replies

  • User1269925535 posted

    hi...try this:

    this code save file with DateTime Name...

     int index = File1.FileName.LastIndexOf('.');
            string ext = "";
            if (index > 0)
                ext = File1.FileName.Substring(index);
            string fileName = DateTime.Now.ToString().Substring(0, 19).Replace("/", ".").Replace(":",".") + "_" + category + ext;
            string path = Server.MapPath("~/PDFFiles/" + fileName);
            File1.SaveAs(path);
            return fileName;



    Thursday, November 26, 2009 2:30 AM
  • User-1098651225 posted

    Hi

    Go to the this link : http://www.wrox.com/WileyCDA/Section/id-292158.html

     Enjoy :)

    Monday, November 30, 2009 10:19 AM