question

SathyanarayananAV-9576 avatar image
0 Votes"
SathyanarayananAV-9576 asked LanHuang-MSFT commented

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

// 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,
dotnet-aspnet-mvc
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am trying to create a test environment in my local machine. When i debug the code i am getting this error.

0 Votes 0 ·

1 Answer

AgaveJoe avatar image
0 Votes"
AgaveJoe answered LanHuang-MSFT commented

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


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Many thanks for your reply. I am not able to add the assembly file in VS 2017. When i try to use system.io.file; in the using statement; it is not listed.

kindly give your feedback.
Cheers
Sathya

0 Votes 0 ·
LanHuang-MSFT avatar image LanHuang-MSFT SathyanarayananAV-9576 ·

Hi @SathyanarayananAV-9576,
File is the name of one of the controllers methods, if you want to reference the File class from System.IO namespace, you need to fully qualify the name.
You just need to change File.ReadAllBytes to System.IO.File.ReadAllBytes.
240435-99.gif
Best regards,
Lan Huang


0 Votes 0 ·
99.gif (94.9 KiB)