ASPX page for file upload:

<%@ Page language="c#" Codebehind="GetFile.aspx.cs" AutoEventWireup="false" Inherits="fulltext.GetFile" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

<HEAD>

<title>GetFile</title>

<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">

<meta content="C#" name="CODE_LANGUAGE">

<meta content="JavaScript" name="vs_defaultClientScript">

<meta content=" name="vs_targetSchema">

</HEAD>

<body>

<form id="Form1" method="post" encType="multipart/form-data" runat="server">

<TABLE border="0">

<tr>

<td>Title:<asp:textbox id="tbTitle" runat="server"</asp:textbox</td>

</tr>

<tr>

<td<br</td>

</tr>

<TR>

<TD>Select a File to Include for Search</TD>

</TR>

<TR>

<TD<INPUT id="fileToAdd" type="file" runat="server"</TD>

</TR>

<tr>

<td<br</td>

</tr>

<tr>

<td<asp:Button id="btnUp" runat="server" Text="Upload"</asp:Button</td>

</tr>

</TABLE>

</form>

</body>

</HTML>

CODE BEHIND PAGE:

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.IO;//for file control

using System.Data.SqlClient;//for stored proc

namespace fulltext

{

/// <summary>

/// Summary description for GetFile.

/// </summary>

public class GetFile : System.Web.UI.Page

{

protected System.Web.UI.HtmlControls.HtmlInputFile fileToAdd;

protected System.Web.UI.WebControls.TextBox tbTitle;

protected System.Web.UI.WebControls.Button btnUp;

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.btnUp.Click += new System.EventHandler(this.btnUp_click);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void btnUp_click(object sender, System.EventArgs e)

{

//get document from the stream

int iDocLength = fileToAdd.PostedFile.ContentLength;

byte[] bDocTemp = new byte[iDocLength];

Stream objStream;

objStream = fileToAdd.PostedFile.InputStream;

objStream.Read(bDocTemp, 0, iDocLength);

//get extension type, the last three chars after the period in the file name

string sExt = fileToAdd.PostedFile.FileName.ToString();

sExt = sExt.Substring(sExt.IndexOf(".", 0) ,4);

SqlConnection objConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("FullText"));

objConn.Open();

SqlCommand objCmd = new SqlCommand("FileUp", objConn);

objCmd.CommandType = CommandType.StoredProcedure;

SqlParameter pTitle = objCmd.Parameters.Add("@Title", SqlDbType.VarChar,200);

pTitle.Direction = ParameterDirection.Input;

pTitle.Value = tbTitle.Text;

SqlParameter pType = objCmd.Parameters.Add("@Type", SqlDbType.VarChar, 50);

pType.Direction = ParameterDirection.Input;

pType.Value = sExt;

SqlParameter pDocument = objCmd.Parameters.Add("@Document", SqlDbType.Image);

pDocument.Direction = ParameterDirection.Input;

pDocument.Value = bDocTemp;

objCmd.ExecuteNonQuery();

objConn.Close();

}

}

}

STORED PROCEDURE

CREATE PROCEDURE FileUp

(

@Title varchar(200),

@Type varchar(50),

@Document image

)

AS

--rmv the period

SET @Type = RIGHT(@Type, 3)

SET @Type = LOWER(@Type)

INSERT INTO Docs

(Title, Type, Document)

VALUES

(@Title, @Type, @Document)

GO