Exemplo n.º 1
0
        public Models.ApplicationFile GetFilePath(string file_id)
        {
            SqlConnection conn   = new SqlConnection(SLW_dbConn);
            SqlCommand    cmd    = new SqlCommand();
            SqlDataReader reader = null;

            cmd.CommandText = "sp_getFilePath @file_id";
            cmd.Parameters.AddWithValue("@file_id", file_id);
            cmd.Connection = conn;

            conn.Open();
            reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                reader.Read();
                Models.ApplicationFile application = new Models.ApplicationFile(reader["path"].ToString(), reader["filename"].ToString());
                conn.Close();
                return(application);
            }
            else
            {
                conn.Close();
                return(null);
            }
        }
Exemplo n.º 2
0
 public ActionResult Download(string file)
 {
     if (Session["key"] != null)
     {
         try
         {
             Models.ApplicationFile application = GetFilePath(file);
             byte[] fileBytes = System.IO.File.ReadAllBytes(application.path);
             return(File(fileBytes, "application/pdf", application.filename));
         }
         catch (Exception e)
         {
             return(null);
         }
     }
     else
     {
         return(View("NotAuthorizedDownload"));
     }
 }
Exemplo n.º 3
0
 public ActionResult GetFile(string file)
 {
     if (Session["key"] != null)
     {
         try
         {
             Models.ApplicationFile application = GetFilePath(file);
             byte[] fileBytes = System.IO.File.ReadAllBytes(application.path);
             Response.AppendHeader("Content-Disposition", "inline; filename=\"" + application.filename + "\"");
             return(File(fileBytes, "application/pdf"));
         }
         catch (Exception e)
         {
             return(null);
         }
     }
     else
     {
         return(View("NotAuthorizedView"));
     }
 }