Utils.GetFileInfo error - c#

I'm going through the sample projects of EPPlus and finally reached the part that I'm interested in. I would like to import contents of a .txt file. Sample 9 shows how to do this, but I get an error I can't seem to fix.
The error message:
The type or namespace name "GetFileInfo" doesn't exist in the namespace 'OfficeOpenXml.Utils'(are you missing an assembly reference?)
The code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OfficeOpenXml;
using System.IO;
using OfficeOpenXml.Table;
using OfficeOpenXml.Drawing.Chart;
using System.Globalization
...
FileInfo newFile = Utils.GetFileInfo(#"\sample9.xlsx");
Does anyone encountered this issue? Thanks in advance!
Edit: If I open directly the sample file I don't get any errors, only if I try to do it in my own project.

Try this:
var file = new System.IO.FileInfo(fullpathandfilename);

Related

the name properties does not exist in the current context?

I'm getting an error that says the name properties does not exist in the current context? The rest of the code seems fine, apart from this error, I'm aware there are similar questions however I'm struggling to apply the solutions in my own problem.
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace transportservices
public class Service1 : transport
{
public int insertData(string shop, string car, string train)
{
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.SQL_String))
You don't have SQL_String property on your project. To add
Right click your project
Click on Properties
Go to Resources tab
Select Resource type string
In the grid Add SQL_String as Name of your resource name and provide value.
Your project namespace and class consuming that resource should have same namespace else you have to import that namespace in class.
I fixed this by adding a new dummy setting as follow:
then clicking the Save button. All errors saying "the name 'properties' does not exist in the current context" disappeared.

Xamarin - System.IO.File - namespace 'File' does not exist

I am trying to load a local json file into a string such that I can parse/deserialize it into an object.
However for some reason despite all the examples and the Xamarin support documentation suggesting I can use System.IO.File.ReadAllText(...) I get the following error:
c# error: 'File' type or namespace name not found
My code seems pretty simple, I can't get past loading the file, which seems like it should be so simple!
string jsonInput = System.IO.File.ReadAllText("example.json", Encoding.UTF8);
Quiz temp = JsonConvert.DeserializeObject<Quiz>(jsonInput);
My header includes System.IO amongst the rest too..
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel; //ObservableCollection
using Newtonsoft.Json;
using System.IO;
using System.Reflection;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;`
I've also tried the following solution:
var assembly = typeof(LoadResourceText).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream("example.json");
string jsonInput = "";
using (var reader = new System.IO.StreamReader(stream))
{
jsonInput = reader.ReadToEnd();
}
However in this case 'LoadResourceText' is not found and I can't work out what type should replace it.
Any help or suggestions would be greatly appreciated!
My first post on StackOverflow, hope I did it right..
If you are using this file as a local resource, make sure that it is available for each device, for example, in the Android project, select the file/properties/advanced/build action and set it to embedded resource.
Sometimes the code is fine, it's just that the file 'doesn't exist' for the device
^See above response as well^
I have solved this myself.
I found my answer hidden in a forum post by YkshLeo on the Xamarin Forums:
"...make sure the Build Action for your resource is set to "Embedded Resource"
I really wish Xamarin would make their documentation a little more thorough. Maybe it's my .Net noobness coming through.

The type or namespace name does not exist in the namespace (are you missing an assembly reference?)

I know that this question has been already asked, but I cannot find anything that can help solve my problem.
I want to connect my aspx page (Retete.aspx) to a Microsoft SQL database. I'm getting this error on Retete.aspx.cs:
Error 1 The type or namespace name 'GlobalClass' does not exist in the namespace 'ProiectSera' (are you missing an assembly reference?)
The error points to this line of code:
ProiectSera.GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text);
Where ProiectSera is the project name, GlobalClass is the file where I make the operation on the db.
My using statements are:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProiectSera;
The Target Framework is set to .net-4.5.
What should I do to solve this error?
Update
My GlobalClass.cs is:
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.IO;
using ProiectSera;
using System.Data.Services;
namespace ProiectSera.App_Code
{
public static class GlobalClass
{
static public void Update(string _param1, string _param2)
{//function to update}
}
}
App_Code is a folder where GlobalClass.cs is. I tried and
ProiectSera.App_Code.GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text); //
but I had the same error. And I put the GlobalClass.cs in the project's root. I also removed the .App_Code from namespace ProiectSera.App_Code
UPDATE1
My Retete.aspx.cs is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProiectSera;
using ProiectSera.App_Code;
namespace ProiectSera
{
public partial class Retete : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
string intValRefTempSol;
string intValRefTempAer;
// intValRefTempSol = ValRefTempSol.Text;
// intValRefTempAer = ValRefTempAer.Text;
// ProiectSera.App_Code.GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text);
GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text);
}
}
}
Your GlobalClass is in the namespace ProiectSera.App_Code.
So the class name is ProiectSera.App_Code.GlobalClass
Make sure you don't have a ProiectSera class in the ProiectSera namespace also, otherwise if declaring using ProiectSera on top, it'll try to use it (as a general rule, don't name any class the same as your namespace).
If that still doesn't work, you may want to try using the global namespace:
global::ProiectSera.GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text);
and see if that works: if it doesn't, and GlobalClass is in the same project, then there's something else you haven't shown us
Update
The only other thing that comes to mind, if you are positive that both files are on the same project/assembly, is that GlobalClass.cs is not being actually compiled. Make sure the Build Action is set to Compile (you can see the build action right clicking on the GlobalClass.cs in the solution explorer and selecting Properties).
If you are using VS.NET:
Right click on the References folder on your project.
Select Add Reference.
Select the .NET tab (or select the Browse button if it is not a .NET Framework assembly).
Double-click the assembly containing the namespace in the error message.
Press the OK button.
Ensure the following...
That you have a project reference to ProiectSera from your web application, if it's in a separate library. If GlobalClass is in the web application project itself, you won't require this, but if GlobalClass is defined in a separate library in the same solution or elsewhere, then you're going to need to add a reference to that external library in your web application.
Ensure that ProiectSera should not be ProjectSera (if it's a typo).
Ensure that you have your ProiectSera using statement in place at the top (using ProiectSera;). Assuming that this is the correct namespace. Check the namespace of your GlobalClass class and use that using accordingly in the class that wishes to use its functionality.
Then, simply call this in your code, assuming that Update is a static method of GlobalClass.
GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text);
EDIT: given that you've now posted your GlobalClass code, you can see that the namespace for this class is ProiectSera.App_Code;. So you need to have that as your using statement in the other class using ProiectSera.App_Code;. And then call it via simply GlobalClass.Update, as mentioned above.
If you don't understand how namespacing works in C#, then I recommend you check this out (https://msdn.microsoft.com/en-us/library/dfb3cx8s.aspx).

Cannot find the namespace for generic type "List"

I have a strange error and don't know how to solve that. I have a Form which gets opened by another (Main)Form. When I write
List<String> valStoreAsString = new List<String>();
I get "The value or namespace List could not get found". My using directives are the following:
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using System.Runtime.InteropServices;
In the other Forms it works fine. What happened here?
Add following using directive to the list of usings.
using System.Collections.Generic;
Tip
If you are using Visual Studio and if you don't know the namespace then type name of type (Case sensetive) in editor and then press ctrl+ . and select add using option and VS will add related using for you.
or you can right click on name of Type and select Resolve option and select using .... sub option.

"Name 'Process' does not exist in current context" error in console app

I'm trying to use the Process class but it gives me this compiler error every time I do
The name 'Process' does not exist in the current context
I've already added using System.Diagnostics; at the top of my code but I still get this error. Autocomplete wont even recognize the class.
Hear is the code. I've only included the Main method because the rest of the code has nothing to do with the error.
using System;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
public class MainClass
{
static void Main()
{
AIRuntime adam = new AIRuntime("Adam", false);
adam.AIUpdate();
Process.Start(adam.directory); //adam.directory is just a string
}
}
My IDE is Xamarin Studio if it matters.
After web searching and attempts, I found the problem.
To fix this, I manually add a reference to System in my project options instead of just typing using System;. I also need to keep using System.Diagnostics; at the top. It's all in the picture below
Thanks guys for trying to help

Categories

Resources