Click here to Skip to main content
15,892,809 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Can't find Graphics.FromImage Pin
Guffa7-Jan-07 4:31
Guffa7-Jan-07 4:31 
GeneralRe: Can't find Graphics.FromImage Pin
xiaowenjie10-Jan-07 2:42
xiaowenjie10-Jan-07 2:42 
GeneralRe: Can't find Graphics.FromImage Pin
Guffa10-Jan-07 3:33
Guffa10-Jan-07 3:33 
QuestionSyncing two databases in web ! Pin
Hadi Rezaee6-Jan-07 20:49
Hadi Rezaee6-Jan-07 20:49 
Questionhow to store the uploaded file from asp.net page to sqlserver Pin
MD126-Jan-07 18:57
MD126-Jan-07 18:57 
AnswerRe: how to store the uploaded file from asp.net page to sqlserver Pin
Chris Buckett6-Jan-07 22:34
Chris Buckett6-Jan-07 22:34 
GeneralRe: how to store the uploaded file from asp.net page to sqlserver Pin
MD128-Jan-07 20:23
MD128-Jan-07 20:23 
GeneralRe: how to store the uploaded file from asp.net page to sqlserver Pin
Chris Buckett8-Jan-07 21:27
Chris Buckett8-Jan-07 21:27 
The upload function is the same whatever type of document (you can store .doc files in an "Image" datatype - it's just a blob field.

The OnPageLoad function where the file is retrieved:

Assuming the uploaded file is in the table MyTable in a column called MyFile, the mime type of the file is stored in MyFileMIME and the id field is MyID

C#
//pageLoad of GetFile.aspx
//call like: http://www.mywebsite.com/GetFile.aspx?MyID=123
private void Page_Load(object sender, System.EventArgs e)
{
    // Put user code to initialize the page here
    int MyID = Convert.ToInt32(Request.QueryString["MyID"]);

    SqlConnection connection = new 
        SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=india");
    connection.Open ();
    try
    {
        SqlCommand command = new
          SqlCommand("select myFile, myFileMime from MyTable " +
                          "where MyID = @MyID", connection);
        command.Parameters.AddWithValue("@MyID", MyID);

        byte[] myFile = null;
        string myMimeType = "";
        SqlDataReader reader = command.ExecuteReader();
        reader.Read();
        myFile = reader.GetBytes(0, 0, myFile, 0, int.MaxValue); //column 0
        myMimeType = reader.GetString(1); //column 1
    }
    finally
    {
        connection.Close();
    }
        
    Response.Clear();
    Response.ContentType = myMimeType;
                
    // this line replaces the html with the content you send it.
    Response.BinaryWrite(myFile);  

    Response.End();
        
}


The above function takes retrieves both the file data and the mime type from the database (which you would have stored previously. For a word doc it's something like application/word and for a jpeg it's something like image/jpg but you could google mime types for more info (I'm just doing this from memory).

The above function replaces the html in the page with the file you are retrieving, so to use the above to display an image in a web page, you would use html like this:
HTML
in MyHtmlPage.html
<img src="GetFile.aspx?MyID=12345" width="100" height="100">
where file id 12345 is an image

or to retrieve a word doc, you would just put a link to it:
HTML
in myHtmlPage.html
<a href="GetFile.aspx?MyID=12345">Download file</a>
where file id 12345 is a file to download.


One final note: the above page load function is not particularly secure (it's for demonstration purposes only). You should google for info about "sql injection attacks" and modify the data access appropriately.

Hope that helps.

ChrisB
ChrisDoesDev[^]

Questiondistributed cache with .net Pin
SharpSmith6-Jan-07 11:00
SharpSmith6-Jan-07 11:00 
Questionfiltering columns in datagrid Pin
haytham_mohammad6-Jan-07 10:32
haytham_mohammad6-Jan-07 10:32 
AnswerRe: filtering columns in datagrid Pin
Not Active6-Jan-07 13:19
mentorNot Active6-Jan-07 13:19 
QuestionCan you detect the Back Button? Pin
code-frog6-Jan-07 8:51
professionalcode-frog6-Jan-07 8:51 
AnswerRe: Can you detect the Back Button? Pin
Ed.Poore7-Jan-07 6:10
Ed.Poore7-Jan-07 6:10 
Questionuse hidden fields in aspx Pin
raquidd226-Jan-07 8:38
raquidd226-Jan-07 8:38 
AnswerRe: use hidden fields in aspx Pin
seee sharp7-Jan-07 23:02
seee sharp7-Jan-07 23:02 
GeneralRe: use hidden fields in aspx Pin
raquidd229-Jan-07 6:18
raquidd229-Jan-07 6:18 
QuestionProject Compile Pin
Amit Kumar G6-Jan-07 6:59
Amit Kumar G6-Jan-07 6:59 
AnswerRe: Project Compile Pin
Not Active6-Jan-07 7:09
mentorNot Active6-Jan-07 7:09 
QuestionProblem with controls seeking inside DataGrid Pin
Tygrys[work]6-Jan-07 3:20
Tygrys[work]6-Jan-07 3:20 
GeneralHOME WORKERS NEEDED(9261) Pin
kapil khanna6-Jan-07 3:03
kapil khanna6-Jan-07 3:03 
GeneralRe: HOME WORKERS NEEDED(9261) Pin
enjoycrack6-Jan-07 4:47
enjoycrack6-Jan-07 4:47 
GeneralRe: HOME WORKERS NEEDED(9261) Pin
minhpc_bk6-Jan-07 5:12
minhpc_bk6-Jan-07 5:12 
GeneralDisable Combo Box Pin
Monty26-Jan-07 1:52
Monty26-Jan-07 1:52 
GeneralRe: Disable Combo Box Pin
minhpc_bk6-Jan-07 5:09
minhpc_bk6-Jan-07 5:09 
Questiondeploying asp.net on LAN Pin
aransiola6-Jan-07 1:16
aransiola6-Jan-07 1:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.