SQL Procedure
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE UploadFile
@filename varchar(max),
AS
BEGIN
INSERT INTO Table_Name(Uploaded_File)
VALUES ((CONVERT(varbinary (max),@filename)))
END
GO
Asp Code
private void btnUpload_Click(object sender, EventArgs e)
{
if(tbxFileName.Text.Length == 0)
{
MessageBox.Show("Please select a file to upload.");
}
else
{
using (SqlConnection sqlConn = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.Parameters.Add("@filename", SqlDbType.VarChar,200000).Value = text;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "UploadFile";
cmd.Connection = sqlConn;
cmd.Connection.Open();
tbxname.Clear();
tbxfilepath.Clear();
try
{
cmd.ExecuteNonQuery();
}
catch { }
}
}
}