Visual Studio .NET - Uploading any file from server folder
Asked By Anil Desai
08-Jun-06 02:11 AM
I want to download any type of file which is located on server folder.
So how i do it?
re
hi
refer link
http://www.xefteri.com/articles/show.cfm?id=8
use the content-disposition header
If you are using ASP/ASP.NET, you can use the content-disposition header.
Its format is:
Content-disposition: attachment; filename=fname.ext
When Internet Explorer receives the header, it raises a File Download
dialog box whose file name box is automatically populated with the file
name that is specified in the header.
Here is a code snippet in asp.net(C#):
private void Button1_Click(object sender, System.EventArgs e)
{
string strFileToDownload=@"C:\1.jpg";
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;
filename="+System.IO.Path .GetFileName(strFileToDownload));
Response.WriteFile(strFileToDownload);
}
You can check this link for more information.
HOWTO: Raise a "File Download" Dialog Box for a Known MIME Type
http://support.microsoft.com/default.aspx?scid=http://support.microso...
80/support/kb/articles/Q260/5/19.ASP&NoWebContent=1
Hope this helps.

image file upload hi all, how to upload images which are stored on system, using asp.net page and i have to store uploaded images into my solution explorer folder. i need can store into DataBase. Use this sample code for that- protected void btnUpload_Click(object sender, EventArgs e) { byte[] imageSize = new byte[FileUpload1.PostedFile.ContentLength]; HttpPostedFile uploadedImage = FileUpload1.PostedFile; uploadedImage.InputStream.Read uploadasp204(en-us, MSDN.10).gif Check this simple code: protected void btnUpload_Click( object sender, EventArgs e) { if (FileUpload1.HasFile) { try { string FolderPathToSave = Server.MapPath( "~ / images" ); / / Save Image in Images Folder url) values (@name, @url)" , connection); comm.Parameters.AddWithValue( "name" , "file1" ); comm.Parameters.AddWithValue( "url" , Path .GetFileName(FileUpload1.PostedFile.FileName)); comm.ExecuteNonQuery(); connection.Close(); } catch ( Exception ex) { Status.Text = "ERROR: " + ex.Message btnUpload" OnClick = "btnUploadClick" Text = "Upload" / > < / form > In aspx.cs page protected void btnUploadClick( object sender, EventArgs e) { HttpPostedFile file = Request.Files[ "myFile" ]; if (file ! = null && file.ContentLength ) { string fname = Path.GetFileName(file.FileName); file.SaveAs(Server.MapPath(Path.Combine( "~ / App_Data / " , fname))); } } hope this will help you Here is an example uploading images in File System and storing image paths in the DataBase. Get the file name
upload using jquery as explained here thanks for your immediate response I am new to .net, so please can you provide with code. Thanks Satish Hi Satish if you have need Dictionary ( Of String , String ) Protected Sub Page_Init ( ByVal sender As Object , ByVal e As System. EventArgs ) AllowedFileTypes = New Dictionary ( Of String , String ) AllowedFileTypes. Add ( "gif" , "image / gif" ) AllowedFileTypes. Add ( "jpg" , "image text / css" ) End Sub Protected Sub Page_Load ( ByVal sender As Object , ByVal e As System. EventArgs ) Message. InnerHtml = String . Empty Dim FileInputClass As String = String . Empty For Each FileType As String End If End Sub Protected Sub btnUpload_Click ( ByVal sender As Object , ByVal e As System. EventArgs ) 'Make sure Windows User "NETWORK SERVICE" has write permissions! Dim SaveFolder As String = "C: \ Temp AllFiles. Count - 1 ) ThisFile = AllFiles. Get ( i ) If ThisFile. ContentLength > 0 Then ThisFileName = IO. Path . GetFileName ( ThisFile. FileName ) ValidType = False For Each FileTypeList As String In AllowedFileTypes. Values ( ) For Each FileType If Next End Sub Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Message.Visible = Not String.IsNullOrEmpty(Message.InnerHtml) End Sub < / script> <html xmlns = " http: / / www. w3 . org / 1999 / xhtml "> <head runat = " server "> <title> jQuery Multi Upload with ASP.NET< / title> <script src = " http: / / ajax. googleapis . com / ajax / libs / jquery / 1.3.2 / jquery. min
show image in image control through this image path. . when page loads. . i am using asp.net C# with visual studio 2008 and sql server 2005. thanx in advance. . hi, use this below uploading images in File System and storing image paths in the DataBase. Get the file name save to a folder and save the path to database protected void btnSubmit_Click(object sender, EventArgs e) { / / Get Filename from fileupload control string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName); / / Save images into Images folder fileuploadimages.SaveAs(Server.MapPath("Images / "+filename)); / / Getting assign to ImageUrl Property of Image Control. try this code- protected void GetDetails_Click(object sender, EventArgs e) { { SqlConnection con = new SqlConnection("con string "); SqlDataAdapter da; string mySQL = "SELECT imgPath FROM emptable
as "Browse" which should browse fa the Project Location similar to what we have in Visual studio 2008 HI Try this code private void buttonBrowse_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); CenariosText.Text = openFileDialog1.FileName; } Hope it helps. . . Hi, Like browse we have Fileupload control in .Net please check this As the move is made to more sophisticated internet applications, users expect code for a simple Web app I'll show you how to create a simple ASP.NET Web application that demonstrates uploading a file to a server. The C# code is available in Listing A , and the you can follow the steps I took to build this project. First, you fire up Visual Studio .NET. On the Start Page, click on the New Project button. Choose the following
Image upload using FIle upload control hi, in my asp.net web application, i have taken one webform named "Default2.aspx", in the design view, i displayed in Image control! how to do this?? pls give any solution! i m using Visual studio 2010! In the button click you can write this code to show image in Image OnClick = "Button1_Click" / > <asp:Image ID = "Image1" runat = "server" / > / / in code protected void Button1_Click(object sender, EventArgs e) { string path = Server.MapPath("images / ") + FileUpload1.PostedFile.FileName; FileUpload1.SaveAs(path); Image1.ImageUrl = "images 3: < br / > 4: < asp:Image ID = "Image1" runat = "server" / > And here's the code for uploading the image to a folder. CODE BEHIND: 1: protected void Button1_Click( object sender, EventArgs e) { 2: StartUpLoad(); 3: } 4: 5: private void StartUpLoad() { 6: / / get the file name of application what my mean to say . . . if for example is located in E: \ Practice \ Sample \ Asp.net \ Lab1 say this is the path of your application so inside this you have