0

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 ?
?

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by HunainHafeez
1

//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;
            }

Edited by kkunodziya

1
           //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;
            }

Edited by kkunodziya

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.