Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2007, 07:03 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Download file that stored in sql server

Hi,
I have tried to implement file download option. I can download file which is stored in any folder. Code is...

        string filepath = Request.Params["file"].ToString();
        string filename = Path.GetFileName(filepath);
        Response.Clear();
        Response.ContentType = "image/gif";
        Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
        Response.Flush();
        Response.WriteFile(filepath);

This code is working fine. Now I want to store the file in database table. User can download file from the database. How can I do this? The file may be a .txt, .doc, .xls, .jpg or .gif.

__________________
Angshujit
 
Old February 20th, 2007, 08:50 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You will need to convert your file to a byte stream and place it in your SQL Server in a column of type image. You will also need to store the length and content type of the uploaded file so that you can push it back down to the client correctly.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
 
Old February 20th, 2007, 09:40 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your reply. I have tried it. It is showing an error. Code is...
    string name = fLoad.FileName;
    System.IO.Stream str = fLoad.FileContent;
    int len = (int)str.Length;
    Byte[] byteData = new Byte[len];
    str.Write(byteData, 0, len); //Error is here

And the error is...
     Specified method is not supported.
How to fix it?
Angshujit
 
Old February 20th, 2007, 09:51 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Read this.

http://www.developer.com/net/asp/article.php/3097661

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
 
Old February 20th, 2007, 10:15 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Woh...its working. Thank you. How can I download that file? I know how to download file from a folder. But from database?

Angshujit

 
Old February 20th, 2007, 10:17 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

On that same page read about the Method DeliverFile. It explains it point blank.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
 
Old February 21st, 2007, 06:40 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

At last... it is working...
Now, user can upload any type of files. I have written the Response.ContentType for .txt, .doc, .xls, .jpg, .jpeg, .gif and .pdf. Now if any user upload any other file then in the time of download I want to zip that file before download. How can I zip a file?
Angshujit

 
Old February 21st, 2007, 08:59 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You should really try researching this stuff before you post a question. Google is a great resource, use it. http://www.aspheute.com/english/20011115.asp

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
 
Old February 22nd, 2007, 06:37 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK. it is working....
Sorry to post this type of question. Since I am new in .net so I have posted this question.

Angshujit






Similar Threads
Thread Thread Starter Forum Replies Last Post
Download in Image from Sql Server 2000 using asp surendraparashar Classic ASP Basics 0 December 16th, 2007 11:55 PM
2003 Server - allow sensitive file download mat41 Windows Server 1 November 18th, 2007 01:53 PM
File download from another server harshaghanta ASP.NET 1.0 and 1.1 Basics 1 August 18th, 2006 12:37 PM
Download an exe file from server to Client balakumar1000 Classic ASP Basics 1 November 17th, 2003 06:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.