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

ASP.NET

 
AnswerRe: resolve Url and catch Query String Pin
Anurag Gandhi13-Feb-10 6:37
professionalAnurag Gandhi13-Feb-10 6:37 
AnswerRe: resolve Url and catch Query String Pin
Not Active13-Feb-10 7:28
mentorNot Active13-Feb-10 7:28 
AnswerRe: resolve Url and catch Query String Pin
Hesham Amin13-Feb-10 7:33
Hesham Amin13-Feb-10 7:33 
GeneralRe: resolve Url and catch Query String Pin
kasraa0009800013-Feb-10 12:32
kasraa0009800013-Feb-10 12:32 
QuestionProblem with GridView [modified] Pin
Sider8913-Feb-10 4:04
Sider8913-Feb-10 4:04 
AnswerRe: Problem with GridView Pin
Anurag Gandhi13-Feb-10 6:31
professionalAnurag Gandhi13-Feb-10 6:31 
AnswerRe: Problem with GridView Pin
Sider8914-Feb-10 2:57
Sider8914-Feb-10 2:57 
Questionproblem with uploading/downloading .docx file Pin
shankbond13-Feb-10 3:18
shankbond13-Feb-10 3:18 
Hi, I have a problem similar to this post:



http://www.microsoft.com.nsatc.net/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.office.developer.vba&tid=6fc07fd9-3313-4c09-9457-f6971ecafda4&cat=en_US_9477b478-d551-48fe-b931-e0d7ed05ac44&lang=en&cr=US&sloc=&p=1



In this post the original poster has written his code in VB whereas I have written my code in C#

My code for uploading a file:

protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.PostedFile.ContentLength>0)
        {
            string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
            string storagepath = "D:\\Test\\" + filename;
            int contentLen = FileUpload1.PostedFile.ContentLength;
            Byte[] data = new Byte[contentLen];
            FileUpload1.PostedFile.InputStream.Read(data, 0, contentLen);
            savefiletodatabase(data); 
            FileUpload1.SaveAs(storagepath);
        }
    }




 private void savefiletodatabase(byte[] data) 
    {
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        try
        {
            SqlCommand command = new SqlCommand("INSERT into dbo.test ([file], [filename], [path]) VALUES (@data, '" + FileName + "', '" + FilePath + "')", connection);
            command.Parameters.AddWithValue("data", data);
            connection.Open();
            command.Connection = connection;
            command.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally { connection.Close(); }
    }




The code to retrieve file goes here:

protected void LinkButton1_Click(object sender, EventArgs e)
    {
        getfile();
    }



    private void getfile() 
    {
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        try
        {
            SqlCommand command = new SqlCommand("Select [file] FROM dbo.test where id='" + Id + "'", connection);
            SqlDataReader reader;
            connection.Open();
            command.Connection = connection;
            reader = command.ExecuteReader();
            if (reader.Read())
            {

                byte[] data = (byte[])reader[0];
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment;filename=" + TextBox2.Text);
                Context.Response.BinaryWrite(data);
            }
        }
        catch (Exception ex) 
        { throw ex; }
        finally
        {
            connection.Close();
        }
       
    }


I am giving You the table structure here:




/****** Object:  Table [dbo].[test]    Script Date: 02/13/2010 19:30:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[test](
	[file] [varbinary](max) NULL,
	[filename] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[path] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[id] [int] IDENTITY(1,1) NOT NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF


please help me out;

also when I uploaded a file to the database it was of 18041 bytes, but when I retrieved it after saving on desktop the size was 19,756 bytes which is increased?
Thanks
Shankbond

AnswerRe: problem with uploading/downloading .docx file Pin
Hesham Amin13-Feb-10 7:40
Hesham Amin13-Feb-10 7:40 
GeneralRe: problem with uploading/downloading .docx file Pin
shankbond13-Feb-10 23:13
shankbond13-Feb-10 23:13 
Questionvedio confernce in asp.net Pin
harilatha12-Feb-10 19:45
harilatha12-Feb-10 19:45 
AnswerRe: vedio confernce in asp.net Pin
Abhijit Jana12-Feb-10 20:13
professionalAbhijit Jana12-Feb-10 20:13 
GeneralRe: vedio confernce in asp.net Pin
harilatha12-Feb-10 20:28
harilatha12-Feb-10 20:28 
GeneralRe: vedio confernce in asp.net Pin
sashidhar12-Feb-10 22:05
sashidhar12-Feb-10 22:05 
Questiondesigner appear empty after change source of page Pin
kasraa0009800012-Feb-10 9:58
kasraa0009800012-Feb-10 9:58 
AnswerRe: designer appear empty after change source of page Pin
keyur satyadev12-Feb-10 18:57
keyur satyadev12-Feb-10 18:57 
QuestionRe: designer appear empty after change source of page Pin
kasraa0009800013-Feb-10 5:37
kasraa0009800013-Feb-10 5:37 
Questioniframe pop working in IE but not in FireFox Pin
kamran pervaiz12-Feb-10 1:47
kamran pervaiz12-Feb-10 1:47 
AnswerRe: iframe pop working in IE but not in FireFox Pin
T M Gray12-Feb-10 5:14
T M Gray12-Feb-10 5:14 
QuestionClickheat Clickmap? Pin
emiliovillarox12-Feb-10 0:18
emiliovillarox12-Feb-10 0:18 
QuestionIIS problem in asp.net Pin
JC.KaNNaN12-Feb-10 0:00
JC.KaNNaN12-Feb-10 0:00 
AnswerRe: IIS problem in asp.net Pin
Abhijit Jana12-Feb-10 1:54
professionalAbhijit Jana12-Feb-10 1:54 
QuestionSQL SErver REplication Pin
satsumatable11-Feb-10 23:15
satsumatable11-Feb-10 23:15 
AnswerRe: SQL SErver REplication Pin
Eddy Vluggen12-Feb-10 2:00
professionalEddy Vluggen12-Feb-10 2:00 
Questionsending mail through smtp Pin
amitamit09911-Feb-10 22:48
amitamit09911-Feb-10 22:48 

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.