public MyFile[] GetFiles(string folderpath)
        {
            List<MyFile> myfiles = new List<MyFile>();

            foreach (string filepath in Directory.GetFiles(folderpath))
            {
                MyFile myfile = new MyFile();
                myfile.Path = filepath;
                FileInfo fi = new FileInfo(filepath);
                myfile.Extension = fi.Extension.TrimStart(new char[] { '.' });

                if (myfile.Extension.Equals("txt", StringComparison.OrdinalIgnoreCase))
                {
                    myfile.ContentType = "text/plain";
                }
                else
                {
                    myfile.ContentType = "unknown/unknown";
                }

                myfile.LastModified = fi.LastWriteTimeUtc;
                myfile.Name = fi.Name;
                FileSecurity sec = fi.GetAccessControl();
                myfile.SecurityDescriptor = new Byte[sec.GetSecurityDescriptorBinaryForm().Length];
                myfile.SecurityDescriptor = sec.GetSecurityDescriptorBinaryForm();
                myfiles.Add(myfile);
            }

            return myfiles.ToArray();
        }
 public MyFile GetSpecifiedFile(string filepath)
 {
     if (File.Exists(filepath))
     {
         FileInfo fi     = new FileInfo(filepath);
         MyFile   myfile = new MyFile();
         myfile.Path         = filepath;
         myfile.Extension    = fi.Extension.TrimStart(new char[] { '.' });
         myfile.LastModified = fi.LastWriteTimeUtc;
         myfile.Name         = fi.Name;
         FileSecurity sec = fi.GetAccessControl();
         myfile.SecurityDesciptor = new Byte[sec.GetSecurityDescriptorBinaryForm().Length];
         myfile.SecurityDesciptor = sec.GetSecurityDescriptorBinaryForm();
         return(myfile);
     }
     return(null);
 }
        public MyFile GetSpecifiedFile(string filepath)
        {
            if (File.Exists(filepath))
            {
                FileInfo fi     = new FileInfo(filepath);
                MyFile   myfile = new MyFile();
                myfile.Path         = filepath;
                myfile.Extension    = fi.Extension.TrimStart(new char[] { '.' });
                myfile.LastModified = fi.LastWriteTimeUtc;
                myfile.Name         = fi.Name;
                FileSecurity sec = fi.GetAccessControl();
                myfile.SecurityDesciptor = new Byte[sec.GetSecurityDescriptorBinaryForm().Length];
                myfile.SecurityDesciptor = sec.GetSecurityDescriptorBinaryForm();

                try
                {
                    XDocument xmlDoc   = XDocument.Load(filepath);
                    var       products = from product in xmlDoc.Descendants("Product")
                                         select new
                    {
                        SKU         = product.Element("SKU").Value,
                        Title       = product.Element("Title").Value,
                        Category    = product.Element("Category").Value,
                        Price       = product.Element("Price").Value,
                        Description = product.Element("Description").Value,
                    };
                    // we don't really look for multiple products..we assume 1 per xml doc
                    foreach (var product in products)
                    {
                        myfile.SKU         = product.SKU;
                        myfile.Title       = product.Title;
                        myfile.Category    = product.Category;
                        myfile.Description = product.Description;
                        myfile.Price       = Convert.ToInt32(product.Price);
                    }
                }
                catch (Exception e) {       //just move along
                    myfile.Title = "error"; //this is for debugging only
                }

                return(myfile);
            }
            return(null);
        }
        public MyFile[] GetAllFiles(string folderpath)
        {
            List <MyFile> myfiles = new List <MyFile>();

            foreach (string filepath in Directory.GetFiles(folderpath))
            {
                MyFile myfile = new MyFile();
                myfile.Path = filepath;
                FileInfo fi = new FileInfo(filepath);
                myfile.Extension    = fi.Extension.TrimStart(new char[] { '.' });
                myfile.LastModified = fi.LastWriteTimeUtc;
                myfile.Name         = fi.Name;
                FileSecurity sec = fi.GetAccessControl();
                myfile.SecurityDesciptor = new Byte[sec.GetSecurityDescriptorBinaryForm().Length];
                myfile.SecurityDesciptor = sec.GetSecurityDescriptorBinaryForm();
                myfiles.Add(myfile);
            }

            return(myfiles.ToArray());
        }
        public MyFile GetSpecifiedFile(string filepath)
        {
            if (!File.Exists(filepath))
            {
                throw new Microsoft.BusinessData.Runtime.ObjectNotFoundException(String.Format(
                    "No file exists at the path {0}",
                    filepath));
            }

            FileInfo fi = new FileInfo(filepath);
            MyFile myfile = new MyFile();
            myfile.Path = filepath;
            myfile.Extension = fi.Extension.TrimStart(new char[] {'.'});

            if (myfile.Extension.Equals("txt", StringComparison.OrdinalIgnoreCase))
            {
                myfile.ContentType = "text/plain";
            }
            else
            {
                myfile.ContentType = "unknown/unknown";
            }

            myfile.LastModified = fi.LastWriteTimeUtc;
            myfile.Name = fi.Name;
            FileSecurity sec = fi.GetAccessControl();
            myfile.SecurityDescriptor = new Byte[sec.GetSecurityDescriptorBinaryForm().Length];
            myfile.SecurityDescriptor = sec.GetSecurityDescriptorBinaryForm();
            return myfile;
        }