Im working on a project in which i have to upload a file. I have tried WebHttpRequest class and WebClient class to do this but could not succeed. So, if i programmaticall y fill and click the choose file dialog then it can be done otherwise not. Im using C# for this project.
How can i fill “Choose File Upload Dialog” programmatically using C#
Collapse
X
-
well for uploading files into the database using a file upload lets assume uploading images you can do as follows
now you can save the file by your query into the database..Code:if (fuPhoto.HasFile) // fuPhoto is the name of file upload { string path = Server.MapPath("~/profile/"); string file = fuPhoto.PostedFile.FileName; fuPhoto.SaveAs(path + file); string[] ext = file.Split('.'); if (Request.Cookies["ProfilePic"] == null && Request.Cookies["Extension"] == null) { HttpCookie profileCookie = new HttpCookie("ProfilePic"); profileCookie.Value = ext[0].ToString() + "." + ext[1].ToString(); profileCookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(profileCookie); HttpCookie extensionCookie = new HttpCookie("Extension"); extensionCookie.Value = ext[1].ToString(); extensionCookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(extensionCookie); } else { Response.Cookies["ProfilePic"].Value = ext[0].ToString() + "." + ext[1].ToString(); Response.Cookies["Extension"].Value = ext[1].ToString(); } if (!ClientScript.IsStartupScriptRegistered("alert")) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "alert('File has been uploaded..'); } }
...
AddanComment
-
Ok so yes you are dealing with a webpage.
For security reasons, browser do not let you autofill the the values for file uploads.
You could *TRY* making a customized silverlight control(think activeX or a java applet) for the webpage, but seems a bit exccessive.Comment
-
@Mudassir,
You wrote in first uploading a file in database. but you may be used file system here. isn't it?Comment
Comment