I’m trying to create a copy of a file i have in my database as a byte array, I’m looking for the easiest way to do this, and on SO and everywhere else the answer seems to be:
File.WriteAllBytes(string newfilepath, byte[] theFile);
However I’m unable to use pretty much anything from the File class, and as soon as I type in File. intellisense draws a red line underneath it and says:
cannot choose method from method group did you intend to invoke the method?
I realise this is a very generic question, and the solution is most probably a very simple one, but I can’t figure it out for the life of me. Any ideas?
And here is the code where I try to create the file:
var labProcessOrderLetter = from obj1 in context.LabArticles
join obj2 in context.ProcessLabs
on obj1.ProcessForLabID equals obj2.ID
where obj1.ID == _articleId
select obj2.LetterAttachment;
byte[] thePDFLetter = (byte[]) labProcessOrderLetter.FirstOrDefault();
var uploadPath = Server.MapPath("~/_TEMP/PDF");
var tempfilename = Guid.NewGuid().ToString();
var tempfilenameandlocation = Path.Combine(uploadPath, Path.GetFileName(tempfilename));
File.WriteAllBytes( tempfilenameandlocation, thePDFLetter);
EDIT: Obviously I have already imported the System.IO namespace, and nowhere in my project I have a method or class called File, or even beginning with File.
It sounds like you have a method that’s visible to you (in the same class, say) called
File. This will be chosen in preference toSystem.IO.File. So you need to fully qualify the name:(In fact, enough clues were in the question. It’s
Controller.Filethat’s in scope)