how to add video from database without url?

my name is omer and i m a student. i created a website and i wnat that the user will upload a video. i used a ole object to add db and i succed but im having trouble to adding the video from db to the website. i dont want to save the file in folder and than use url. is it posiblle? the code: App_Data:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;

public class MyVideoHelper
    public MyVideoHelper()


    //הפונקציה מקבלת מסלול של קובץ ומחזירה את הקובץ מומר לבייטים
    public  byte[] ConvertFileToByte(Stream file)
        byte[] video = null;

        BinaryReader br = new BinaryReader(file);
        video = br.ReadBytes((int)(file.Length));

        return video;
    public FileStream ConvertByteToFile( byte[] file)
        Stream stream = new MemoryStream(file);
        FileStream filestream = stream as FileStream;
        return filestream;


the sapx.cs

MyVideoHelper x = new MyVideoHelper();
            string hero3 = Request.Form["hero3"];
            if (Session["loggedIn"] != "true")
                Response.Write("<script>alert('You Are not SignIN!');</script>");
            if ((video2.PostedFile != null) && (video2.PostedFile.ContentLength > 0))
                Stream fs = video2.PostedFile.InputStream;
                string command = "INSERT INTO videos (hero, file) VALUES( '" + hero3 + "','" + x.ConvertFileToByte(fs) + "')";
                MyAdoHelper.DoQuery("omerwatchdb.accdb", command);


            string sql = "SELECT file FROM videos";
            DataTable info = MyAdoHelper.ExecuteDataTable("omerwatchdb.accdb", sql);
            string omer;
            omer = info.Rows[2][0].ToString();
            byte[] bytes = Encoding.ASCII.GetBytes(omer);
             vid = x.ConvertByteToFile(bytes);

1 answer

  • answered 2020-03-31 11:01 JonasH

    If you are going to insert a video file into a database (and you should probably not), then you should treat it as binary data, i.e. a BLOB column. To insert data you should use "parameterized query" where specify the data for the SQL command separate from command itself.

    you could follow an example on how to add a image file. The process will be identical for a video. And here is an article on how to retrieve the data.