Controller.File(byte[], string) is a method, which is not valid in the given context.

SathyanarayananAV 1 Reputation point
2022-09-12T15:12:46.59+00:00

// Decompiled with JetBrains decompiler
// Type: SBLT2.Controllers.MasterController
// Assembly: SBLT2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8E21585E-87B0-453D-9C99-D87F239AF715
// Assembly location: D:\Software\SBLTP\bin\SBLT2.dll

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using SriPravanTech;
using System;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web;
using System.Web.Mvc;

namespace SBLT2.Controllers
{
public class MasterController : Controller
{
public ActionResult Index() => (ActionResult) this.View();

public ActionResult Employee_Salary_Details() => (ActionResult) this.View();  

public ActionResult Milage_Change_History() => (ActionResult) this.View();  

public ActionResult Block_Vehicle() => (ActionResult) this.View();  

public ActionResult Block_Driver() => (ActionResult) this.View();  

public ActionResult Block_Company() => (ActionResult) this.View();  

public ActionResult Block_Route() => (ActionResult) this.View();  

public ActionResult Block_Staff() => (ActionResult) this.View();  

public ActionResult Company_Master() => (ActionResult) this.View();  

public ActionResult Shift_Master() => (ActionResult) this.View();  

public ActionResult Vehicle_Documents() => (ActionResult) this.View();  

public ActionResult Category_Vehicle() => (ActionResult) this.View();  

public ActionResult Block_List() => (ActionResult) this.View();  

public ActionResult Route_Master() => (ActionResult) this.View();  

public ActionResult Attachment_Vehicle() => (ActionResult) this.View();  

public ActionResult Driver_Master() => (ActionResult) this.View();  

public ActionResult Staff_Master() => (ActionResult) this.View();  

public ActionResult Bunk_Master() => (ActionResult) this.View();  

public ActionResult Reference_Master() => (ActionResult) this.View();  

public ActionResult Vehicle_Master() => (ActionResult) this.View();  

public ActionResult Other_Staffs() => (ActionResult) this.View();  

public ActionResult Vehicle_Company_Master() => (ActionResult) this.View();  

public ActionResult Driver_Millage_Bata() => (ActionResult) this.View();  

public ActionResult Vehicle_Driver_Master() => (ActionResult) this.View();  

public ActionResult pr_Print_Driver_Profile(string id)  
{  
  DataTable table1 = dbFunctions.getTable("pr_Print_Driver_Profile  '" + id + "'");  
  try  
  {  
    byte[] numArray = File.ReadAllBytes(Path.Combine(this.Server.MapPath("~/FileUpload/"), table1.Rows[0]["DM_vCode"].ToString() + ".jpg"));  
    SqlConnection sqlConnection = new SqlConnection(dbFunctions.connectionstring);  
    sqlConnection.Open();  
    SqlCommand sqlCommand = new SqlCommand();  
    sqlCommand.Connection = sqlConnection;  
    sqlCommand.CommandType = CommandType.StoredProcedure;  
    sqlCommand.CommandText = "pr_update_Image";  
    sqlCommand.Parameters.Add("@id", SqlDbType.VarChar).Value = (object) id;  
    sqlCommand.Parameters.Add("@DM_image ", SqlDbType.Image).Value = (object) numArray;  
    sqlCommand.ExecuteNonQuery();  
    sqlConnection.Close();  
  }  
  catch (Exception ex)  
  {  
  }  
  DataTable table2 = dbFunctions.getTable("pr_Print_Driver_Profile  '" + id + "'");  
  ReportClass reportClass = new ReportClass();  
  reportClass.FileName = this.Server.MapPath("~/CrystalReport/Driver_Profile.rpt");  
  reportClass.Load();  
  reportClass.SetDataSource(table2);  
  return (ActionResult) this.File(reportClass.ExportToStream(ExportFormatType.PortableDocFormat), "application/pdf");  
}  

public ActionResult pr_Print_Staff_Profile(string id)  
{  
  DataTable table1 = dbFunctions.getTable("pr_Print_Driver_Profile  '" + id + "'");  
  try  
  {  
    byte[] numArray = File.ReadAllBytes(Path.Combine(this.Server.MapPath("~/FileUpload/"), table1.Rows[0]["DM_vCode"].ToString() + ".jpg"));  
    SqlConnection sqlConnection = new SqlConnection(dbFunctions.connectionstring);  
    sqlConnection.Open();  
    SqlCommand sqlCommand = new SqlCommand();  
    sqlCommand.Connection = sqlConnection;  
    sqlCommand.CommandType = CommandType.StoredProcedure;  
    sqlCommand.CommandText = "pr_update_Image";  
    sqlCommand.Parameters.Add("@id", SqlDbType.VarChar).Value = (object) id;  
    sqlCommand.Parameters.Add("@DM_image ", SqlDbType.Image).Value = (object) numArray;  
    sqlCommand.ExecuteNonQuery();  
    sqlConnection.Close();  
  }  
  catch (Exception ex)  
  {  
  }  
  DataTable table2 = dbFunctions.getTable("pr_Print_Driver_Profile  '" + id + "'");  
  ReportClass reportClass = new ReportClass();  
  reportClass.FileName = this.Server.MapPath("~/CrystalReport/Staff_Profile.rpt");  
  reportClass.Load();  
  reportClass.SetDataSource(table2);  
  return (ActionResult) this.File(reportClass.ExportToStream(ExportFormatType.PortableDocFormat), "application/pdf");  
}  

public ActionResult pr_print_Route_Details(string id)  
{  
  DataTable table = dbFunctions.getTable("pr_print_Route_Details  '" + id + "'");  
  ReportClass reportClass = new ReportClass();  
  reportClass.FileName = this.Server.MapPath("~/CrystalReport/Print_Route_Details.rpt");  
  reportClass.Load();  
  reportClass.SetDataSource(table);  
  return (ActionResult) this.File(reportClass.ExportToStream(ExportFormatType.PortableDocFormat), "application/pdf");  
}  

public ActionResult p_print_Company_Address(string id)  
{  
  DataTable table = dbFunctions.getTable("p_print_Company_Address  '" + id + "'");  
  ReportClass reportClass = new ReportClass();  
  reportClass.FileName = this.Server.MapPath("~/CrystalReport/Print_Company_Details.rpt");  
  reportClass.Load();  
  reportClass.SetDataSource(table);  
  return (ActionResult) this.File(reportClass.ExportToStream(ExportFormatType.PortableDocFormat), "application/pdf");  
}  

public ActionResult pr_Print_Driver_RelievingForm(string id)  
{  
  DataTable table = dbFunctions.getTable("pr_Print_Driver_Profile  '" + id + "'");  
  ReportClass reportClass = new ReportClass();  
  reportClass.FileName = this.Server.MapPath("~/CrystalReport/Driver_Reliving_pdf.rpt");  
  reportClass.Load();  
  reportClass.SetDataSource(table);  
  return (ActionResult) this.File(reportClass.ExportToStream(ExportFormatType.PortableDocFormat), "application/pdf");  
}  

public string Pr_Fetch_DriverMilage_VS_Bata_Master_Details() => dbFunctions.GetJSONString(dbFunctions.getTable(nameof (Pr_Fetch_DriverMilage_VS_Bata_Master_Details)));  

public string Pr_Fetch_DriverMilage_VS_Bata_Master_ByID(string ID) => dbFunctions.GetJSONString(dbFunctions.getTable("Pr_Fetch_DriverMilage_VS_Bata_Master_ByID '" + ID + "'"));  

public string Pr_Delete_DriverMilage_VS_Bata_Master(string ID)  
{  
  dbFunctions.getTable("Pr_Delete_DriverMilage_VS_Bata_Master '" + ID + "'");  
  return "True";  
}  

public string Pr_Insert_DriverMilage_VS_Bata_Master(  
  string DB_vMake,  
  string DB_vAvg,  
  string DB_dMin_KM,  
  string DB_dMax_KM,  
  string DB_dMin_Avg,  
  string DB_dMax_Avg,  
  string DB_dAmount,  
  string DB_vCreated_by)  
{  
  SqlConnection sqlConnection = new SqlConnection(dbFunctions.connectionstring);  
  try  
  {  
    sqlConnection.Open();  
    SqlCommand sqlCommand = new SqlCommand();  
    sqlCommand.Connection = sqlConnection;  
    sqlCommand.CommandType = CommandType.StoredProcedure;  
    sqlCommand.CommandText = nameof (Pr_Insert_DriverMilage_VS_Bata_Master);  
    sqlCommand.Parameters.Add("@DB_vMake", SqlDbType.VarChar).Value = (object) DB_vMake;  
    sqlCommand.Parameters.Add("@DB_vAvg", SqlDbType.VarChar).Value = (object) DB_vAvg;  
    sqlCommand.Parameters.Add("@DB_dMin_KM", SqlDbType.VarChar).Value = (object) DB_dMin_KM;  
    sqlCommand.Parameters.Add("@DB_dMax_KM", SqlDbType.VarChar).Value = (object) DB_dMax_KM;  
    sqlCommand.Parameters.Add("@DB_dMin_Avg", SqlDbType.VarChar).Value = (object) DB_dMin_Avg;  
    sqlCommand.Parameters.Add("@DB_dMax_Avg", SqlDbType.VarChar).Value = (object) DB_dMax_Avg;  
    sqlCommand.Parameters.Add("@DB_dAmount", SqlDbType.VarChar).Value = (object) DB_dAmount;  
    sqlCommand.Parameters.Add("@DB_vCreated_by", SqlDbType.VarChar).Value = (object) DB_vCreated_by;  
    sqlCommand.ExecuteNonQuery();  
    sqlConnection.Close();  
    return "True";  
  }  
  catch (Exception ex)  
  {  
    return ex.Message;  
  }  
}  

public string Pr_Update_DriverMilage_VS_Bata_Master(  
  string DB_iid,  
  string DB_vMake,  
  string DB_vAvg,  
Developer technologies | ASP.NET | Other
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2022-09-12T15:53:26.523+00:00

    You created a naming conflict. The Controller class has a File() method and the System.IO has a static File class. Remove the using statement.

    using System.IO;  
    

    Then use the fully qualified name when calling the static File class.

    System.IO.File.ReadAllBytes()  
    

    File.ReadAllBytes(String) Method


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.