Example #1
0
    /// <summary>
    /// แสดงรายการ File ตาม ID ที่ระบุ
    /// </summary>
    /// <param name="Ass_ID">ID ใบประเมิน รวมทั้ง Binary ด้วย</param>
    /// <param name="File_ID">ID ของ File </param>
    /// <param name="ServerMapPath">Physical Root Path</param>
    public static DataTable GetFileByID(int Ass_ID, int File_ID, string ServerMapPath)
    {
        string SQL = "SELECT Ass_ID,File_ID,File_Name,Content_Type,File_Size,IsDefault";
        SQL += " FROM tb_Ass_File WHERE Ass_ID=" + Ass_ID + " AND File_ID=" + File_ID;
        SqlDataAdapter DA = new SqlDataAdapter(SQL, DefaultConnectionString);
        DataTable DT = new DataTable();
        DA.Fill(DT);
        DT.Columns.Add("Content", typeof(byte[]));

        if (DT.Rows.Count > 0)
        {
            string Path = ServerMapPath + "/" + "FileUpload/Ass/" + Ass_ID + "/" + File_ID;
            if (File.Exists(Path))
            {
                FileStream F = File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                Converter C = new Converter();
                DT.Rows[0]["Content"] = C.StreamToByte(F);
                F.Close();
            }
        }
        return DT;
    }