anyone plz help me with it......

i have a signup form in asp.net but the only thing left the facility to upload files to page (server) from hdd e.g pdf, docx, .jpg etc.
now i am using localhost. how to do it ?
?

Recommended Answers

All 3 Replies

//Put a FileUpload control on your form.
//and then try something like below.

             private Boolean UploadFile
             {
             Boolean valid = true;
             string ext;
             string fileName;
            ext = System.IO.Path.GetExtension(fileUpload.PostedFile.FileName);
            fileName = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName);

            string filePath = "";

            if (ext == ".jpg")
                valid = true;
            else if (ext == ".bmp")
                valid = true;
            else if (ext == ".gif")
                valid = true;
            else if (ext == ".png")
                valid = true;
            else
            {
             valid = false;
             lblFeedBack.Text = "Only gif, bmp,jpg or png format files supported.";

             return valid;
            }
            filePath = Server.MapPath("FileFolder");
            filePath += "\\" + fileName;
            fileUpload.PostedFile.SaveAs(filePath);
            return valid;
            }
           //put a FileUpload control on your form and the try the code below.

           private Boolean UploadFile
            {
            Boolean valid = true;
            string ext;
            string fileName;
            if (fileUpload.PostedFile.ContentLength ==0)
            {
                valid = false;

                lblFeedBack.Text = "Browse file";
                 return valid;
            }
            else
            {
                ext = System.IO.Path.GetExtension(fileUpload.PostedFile.FileName);
                fileName = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName);

                string filePath = "";

                if (ext == ".jpg")
                    valid = true;
                else if (ext == ".bmp")
                    valid = true;
                else if (ext == ".gif")
                    valid = true;
                else if (ext == ".png")
                    valid = true;
                else
                {
                    valid = false;
                    lblFeedBack.Text = "Only gif, bmp,jpg or png format files supported.";
                    return valid;
                }
                filePath = Server.MapPath("FileFolder");
                filePath += "\\" + fileName;
                fileUpload.PostedFile.SaveAs(filePath);

            return valid;
            }

wowww @ kkunodziya: you made my day !!! thanks pal !!! :)
SOLVED

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.