Get file from file folder with LINQhttp://forums.asp.net/t/1789662.aspx/1?Get+file+from+file+folder+with+LINQTue, 10 Apr 2012 01:01:35 -040017896624918328http://forums.asp.net/p/1789662/4918328.aspx/1?Get+file+from+file+folder+with+LINQGet file from file folder with LINQ <p>I create a column in my database call the store string path of file locations.</p> <p>This column is FileUrl.&nbsp;</p> <p>I know I can do this in LINQ to get a list of files</p> <p>from f in Directory.GetFiles((@&quot;c:\temp&quot;))</p> <p>select f;</p> <p>to get the list&nbsp;</p> <p></p> <p></p> <p>did this&nbsp;</p> <p>from p in Patients</p> <p>from f in Directory.GetFiles((p.FilesUrl))</p> <p>select f</p> <p></p> <p>I get this error &quot;Method 'System.String[] GetFiles(System.String)' has no supported translation to SQL.&quot;</p> <p></p> <p>How can replace the ((@&quot;c:\temp&quot;)) with&nbsp;((FileUrl))</p> 2012-04-05T15:07:27-04:004918469http://forums.asp.net/p/1789662/4918469.aspx/1?Re+Get+file+from+file+folder+with+LINQRe: Get file from file folder with LINQ <p></p> <blockquote><span class="icon-blockquote"></span> <h4>postonoh</h4> <a title="postonoh" href="/members/postonoh.aspx">postonoh</a></blockquote> <p></p> <p>Not sure did you convert the URL to string?</p> 2012-04-05T17:22:02-04:004918517http://forums.asp.net/p/1789662/4918517.aspx/1?Re+Get+file+from+file+folder+with+LINQRe: Get file from file folder with LINQ <p>tried it still error</p> 2012-04-05T17:53:23-04:004920313http://forums.asp.net/p/1789662/4920313.aspx/1?Re+Get+file+from+file+folder+with+LINQRe: Get file from file folder with LINQ <p></p> <blockquote><span class="icon-blockquote"></span> <h4>postonoh</h4> Method 'System.String[] GetFiles(System.String)' has no supported translation to SQL.&quot;</blockquote> <p></p> <p>Not every statement can be converted into a standard LINQ successfullySo you can use AsEnumerable first to convert from a standard LINQ statement into LINQ-TO-OBJECT and do deal with the problem</p> <pre class="prettyprint">var result = from p in Patients from f in Directory.GetFiles((p.FilesUrl)).<strong>AsEnumerable()</strong> where p.XXX == f select f;</pre> <p><br> <br> </p> 2012-04-07T02:00:51-04:004921398http://forums.asp.net/p/1789662/4921398.aspx/1?Re+Get+file+from+file+folder+with+LINQRe: Get file from file folder with LINQ <p>this is my code how to I incorporate the code you gave me.</p> <p></p> <pre class="prettyprint">public ActionResult Details(int? id) { var patients = ((from p in _db.Patients from f in Directory.GetFiles((p.FilesUrl)).AsEnumerable() join a in _db.AssessmentInformations on p.PatientsId equals a.PatientsId join b in _db.BehaviorInformations on p.PatientsId equals b.PatientsId join c in _db.CurrentMoods on p.PatientsId equals c.PatientsId join d in _db.DietInformations on p.PatientsId equals d.PatientsId join mb in _db.MedicalBackgrounds on p.PatientsId equals mb.PatientsId join med in _db.MedicationInformations on p.PatientsId equals med.PatientsId join ps in _db.PsycologicalBackgrounds on p.PatientsId equals ps.PatientsId join nu in _db.NeurofeedbackInformations on p.PatientsId equals nu.PatientsId join o in _db.OtherDataInformations on p.PatientsId equals o.PatientsId join na in _db.NarrativeInformations on p.PatientsId equals na.PatientsId join s in _db.SupplementsInformations on p.PatientsId equals s.PatientsId select new MyCombinedQueryModel { PatientsId = p.PatientsId, ClientID = p.ClientID, DOB = p.DOB, Gender = p.Gender, Handedness = p.Handedness, RecordingDate = p.RecordingDate, TimeRecording = p.TimeRecording, EO = p.EO, EC = p.EC, Task = p.Task, Referred_for = p.Referred_for, Evaluation_Number = p.Evaluation_Number, Years_of_Education = p.Years_of_Education.Value, Marital_Status = p.Marital_Status, Abnormality = p.Abnormality, Vision = p.Vision, Appearance = p.Appearance, Sleep_Disorder = p.Sleep_Disorder, Accident = p.Accident, Employed = p.Employed, Veteran = p.Veteran, Activities = p.Activities, Overweight = mb.Overweight, Hypertension = mb.Hypertension, Diabetes = mb.Diabetes, TBI = mb.TBI, Migraine = mb.Migraine, Thyroid = mb.Thyroid, Stroke = mb.Stroke, Tremor = mb.Tremor, Parkinson = mb.Parkinson, Kidney = mb.Kidney, Liver = mb.Liver, Lung = mb.Lung, Heart = mb.Heart, Paralysis = mb.Paralysis, Cerebral_Palsy = mb.Cerebral_Palsy, Weakness = mb.Weakness, ADD = ps.ADD, ADD_ADHD = ps.ADD_ADHD, ADHD = ps.ADHD, Anxiety = ps.Anxiety, ASD = ps.ASD, Austism = ps.Autism, Bipolar = ps.Bipolar, Dementia = ps.Dementia, Depression = ps.Depression, Eating_Disorder = ps.Eating_Disorder, Insomnia = ps.Insomnia, LD = ps.LD, OCD = ps.OCD, Psycological_Panic = ps.Psycological_Panic, PDD = ps.PDD, Schizophrenia = ps.Schizophrenia, Seizure = ps.Seizure, Psycological_Other = ps.Psycological_Other, Anxious = c.Anxious, Apprehensive = c.Apprehensive, Cheerful = c.Cheerful, Depressed = c.Depressed, Elevated = c.Elevated, Euphoric = c.Euphoric, Fearful = c.Fearful, Optimistic = c.Optimistic, Panic = c.Panic, Pessimistic = c.Pessimistic, Tearful = c.Tearful, Tense = c.Tense, Worried = c.Worried, Caffeine = d.Caffeine, Tobacco = d.Tobacco, Diet_Other = d.Diet_Other, Exercises = b.Exercises, Violent_Offense = b.Violent_Offense, Violent_Victim = b.Violent_Victim, Trauma = b.Trauma, Speech = b.Speech, Behavior_Other = b.Behavior_Other, Medication = med.Medication, MedDosage = med.MedDosage, Supplements = s.Supplements, SuppDosage = s.SuppDosage, Beck_Despression = a.Beck_Depression, Conners = a.Conners, DSM = a.DSM, IVA = a.IVA, MMSE = a.MMSE, TOVA = a.TOVA, WAIS = a.WAIS, WISC = a.WISC, Assessment_Other = a.Assesment_Other, Therapy_Used = nu.Therapy_Used, Angio = o.Angio, CT = o.CT, EEG = o.EEG, Lumbar = o.Lumbar, MRI = o.MRI, Neuro_Exam = o.Neuro_Exam, X_Ray = o.X_Ray, Other_Data_Other = o.Other_Data_Other, NarrativeSummary = na.NarrativeSummary }).SingleOrDefault(i =&gt; i.PatientsId == id)); return View(patients); }</pre> <p><br> <br> </p> 2012-04-08T05:42:51-04:004921414http://forums.asp.net/p/1789662/4921414.aspx/1?Re+Get+file+from+file+folder+with+LINQRe: Get file from file folder with LINQ <p>Hello</p> <p>Doesn't your code work nowIn fact just use AsEnumerablethe extended methodand in fact you've usedIt should work</p> 2012-04-08T06:18:12-04:004921727http://forums.asp.net/p/1789662/4921727.aspx/1?Re+Get+file+from+file+folder+with+LINQRe: Get file from file folder with LINQ <p>The code works, yes.&nbsp;</p> <p></p> <p>When user click on the detail actionlink. It deplays properly. In my patients table I have a column title FileUrl which capture the dynamic path of the newly created directory. So if when a user creates a new submission form they enter a client ID if the ID exist it attaches a random number at the end then saves the string path to FileUrl. So now I trying to do this, when a client go to look that client ID it display all submitted information but instead of showing the files it is showing the file path.</p> <p>example data is what is being display right now.</p> <p>clientID = 231232</p> <p>DOB 12/08/1970</p> <p>FileUrl = &quot;c:\directory\username\231232\&quot;</p> <p></p> <p>I need this instead&nbsp;</p> <p>clientID = 231232</p> <p>DOB 12/08/1970</p> <p></p> <p>&lt;table&gt;</p> <p>-table grid-</p> <p>FileUrl = list the files in this directory.</p> <p>&nbsp; &lt;/table&gt;</p> <p></p> <p>so instead of the string path.&nbsp;</p> <p>I need to display the files in the directory.</p> <p></p> <p>Thank you for spending time with on this.</p> 2012-04-08T14:24:32-04:004921802http://forums.asp.net/p/1789662/4921802.aspx/1?Re+Get+file+from+file+folder+with+LINQRe: Get file from file folder with LINQ <p>because I am having such a hard time with this do you think I should just save the files in the sql database.</p> <p></p> <p>create a table called Uploaded files with a FK to Patients table and have the files loop through and save them there.&nbsp;</p> <p>Code to read the files instead of pull there locations.</p> 2012-04-08T16:06:23-04:004922046http://forums.asp.net/p/1789662/4922046.aspx/1?Re+Get+file+from+file+folder+with+LINQRe: Get file from file folder with LINQ <p></p> <blockquote><span class="icon-blockquote"></span> <h4>postonoh</h4> <p></p> <p>because I am having such a hard time with this do you think I should just save the files in the sql database.</p> <p>create a table called Uploaded files with a FK to Patients table and have the files loop through and save them there.&nbsp;</p> <p>Code to read the files instead of pull there locations.</p> <p></p> </blockquote> <p></p> <p>YesI think you can do this</p> <p>However if you only want to fetch all the files whose names are something related to thatMaybe you can use <span style="text-decoration:underline"><strong>System.IO.Directory.GetFiles</strong> </span>function do deal with your problem</p> 2012-04-09T01:07:30-04:004923556http://forums.asp.net/p/1789662/4923556.aspx/1?Re+Get+file+from+file+folder+with+LINQRe: Get file from file folder with LINQ <p>&nbsp;I need a additional help.</p> <p></p> <p>I have create the following.&nbsp;</p> <p></p> <p>@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = &quot;multipart/form&quot; }))</p> <p>{</p> <p>}</p> <p>Using this allow me to access the orginal action request..</p> <p>I created a table call FileUpload</p> <p>FileId = PK</p> <p>PatientsId FK</p> <p>BinaryData varbinary(max)</p> <p>Name varchar(255)</p> <p>MimType varchar(255)</p> <p>UploadDate (DateTime)</p> <p>create the the following code</p> <pre class="prettyprint">public int AddFile(byte[] byteArray, string filename, string mimType) { var linqByteArray = new Binary(byteArray); var file = new FileUpload { BinaryData = linqByteArray.ToArray(), MimeType = mimType, Name = filename, UploadDate = DateTime.Now }; _db.SaveChanges(); return file.PatientsId; }</pre> <p><br> I am still having a problem&nbsp;</p> <p>calling the&nbsp;&lt;input type=&quot;file&quot; ID=&quot;file&quot; name=&quot;file&quot; runat=&quot;server&quot; multiple=&quot;multiple&quot; /&gt;</p> 2012-04-09T18:41:37-04:004923861http://forums.asp.net/p/1789662/4923861.aspx/1?Re+Get+file+from+file+folder+with+LINQRe: Get file from file folder with LINQ <p>Hello</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>postonoh</h4> <p></p> <p>I am still having a problem&nbsp;</p> <p>calling the&nbsp;&lt;input type=&quot;file&quot; ID=&quot;file&quot; name=&quot;file&quot; runat=&quot;server&quot; multiple=&quot;multiple&quot; /&gt;</p> <p></p> </blockquote> <p></p> <p>What's the problemAny exceptions or error msgsMaybe another issueIf yesplz create another topic and we'll help</p> <p>Reguards</p> 2012-04-10T01:01:35-04:00