Exemplo n.º 1
0
 //To_Fileは"/Android/data"や"/Download/"などから始める
 public void Upload_File(string From_File, string To_File)
 {
     if (!IsDeviceExsist || !File.Exists(From_File))
     {
         return;
     }
     try
     {
         string phoneDir           = "内部ストレージ" + To_File;
         PortableDeviceFolder root = Device.Root();
         foreach (PortableDeviceObject Name_Now in root.Files)
         {
             MessageBox.Show(Name_Now.Name);
         }
         PortableDeviceFolder result = root.FindDir(phoneDir);
         if (null == result)
         {
             result   = Device.Root().FindDir("Tablet" + To_File);
             phoneDir = "Tablet" + To_File;
             MessageBox.Show("");
         }
         if (null == result)
         {
             return;
         }
         Device.TransferContentToDevice(result, From_File);
     }
     catch (Exception ex)
     {
         Sub_Code.Error_Log_Write(ex.Message);
     }
 }
Exemplo n.º 2
0
        public static bool sendFileToDevice(PortableDevice device, String deviceFolder, String localPath, String localFile, String newNameFile)
        {
            bool status = false;

            try
            {
                String phoneDir             = deviceFolder;
                PortableDeviceFolder root   = device.Root();
                PortableDeviceFolder result = root.FindDir(phoneDir);
                if (null == result)
                {
                    status = false;
                }
                else
                {
                    device.TransferContentToDevice(result, localPath + localFile);
                    status = true;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                status = false;
            }
            return(status);
        }
Exemplo n.º 3
0
        static void Main()
        {
            //Connect to MTP devices and pick up the first one
            var devices = new PortableDeviceCollection();

            devices.Refresh();

            Tablet = devices.First();
            Tablet.Connect();

            //Getting root directory
            var root = Tablet.GetContents();

            //Displayinh directory content in console
            foreach (var resource in root.Files)
            {
                DisplayResourceContents(resource);
            }

            //Finding neccessary folder inside the root
            var folder = (root.Files.FirstOrDefault() as PortableDeviceFolder).
                         Files.FirstOrDefault(x => x.Name == "Folder") as PortableDeviceFolder;

            //Finding file inside the folder
            var file = (folder as PortableDeviceFolder)?.Files?.FirstOrDefault(x => x.Name == "File");

            //Transfering file into byte array
            var fileIntoByteArr = Tablet.DownloadFileToStream(file as PortableDeviceFile);

            //Transfering file into file system
            Tablet.DownloadFile(file as PortableDeviceFile, "\\LOCALPATH");

            //Transfering file rom file system into device folder
            Tablet.TransferContentToDevice("\\LOCALPATH", folder.Id);

            //Transfering file from stream into device folder
            var imgPath = "\\LOCALPATH";
            var image   = Image.FromFile(imgPath);

            byte[] imageB;
            using (var ms = new MemoryStream())
            {
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                imageB = ms.ToArray();
            }
            Tablet.TransferContentToDeviceFromStream("FILE NAME", new MemoryStream(imageB), folder.Id);

            //Close the connection
            Tablet.Disconnect();

            Console.WriteLine();
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }
Exemplo n.º 4
0
        private void transferInputFile(String serviceName)
        {
            Console.WriteLine("Sending input params file to device...");

            if (!File.Exists("input-params"))
            {
                FileStream fs = File.Create("input-params");
                fs.Close();
            }
            using (StreamWriter sw = new StreamWriter(File.Open("input-params", System.IO.FileMode.Truncate))) {
                sw.WriteLine(serviceName);
                foreach (String file in files)
                {
                    String[] parts = file.Split('\\');
                    sw.WriteLine(parts[parts.Length - 1]);
                }
            }

            device.TransferContentToDevice(@Directory.GetCurrentDirectory() + "\\input-params", servicePlatformFolder.Id);
        }