Загрузите файл с C # или PHP в любимые папки с помощью Basic4Android - PullRequest
0 голосов
/ 08 апреля 2019

Как я могу загрузить файл через c # или php мою любимую папку в basic4android? Я могу загрузить через PHP, но я хочу отправить имя папки с параметром вроде как http://xxxx.com/upload.php?folder=foldername и код C # возвращает мне удаленный сервер возвратил ошибку 550 файл недоступен (например, файл не найден, нет доступа) так что я могу отправить из приложения C # Windows с этим кодом: private void sUploadFile (строка имени файла) { пытаться { // получаем точное имя файла по пути String strFile = System.IO.Path.GetFileName (имя файла);

            // create an instance fo the web service
           // TestUploader.Uploader.FileUploader srv = new TestUploader.Uploader.FileUploader();

            // get the file information form the selected file
            FileInfo fInfo = new FileInfo(filename);

            // get the length of the file to see if it is possible
            // to upload it (with the standard 4 MB limit)
            long numBytes = fInfo.Length;
            double dLen = Convert.ToDouble(fInfo.Length / 1000000);

            // Default limit of 4 MB on web server
            // have to change the web.config to if
            // you want to allow larger uploads
            if (dLen < 4)
            {
                // set up a file stream and binary reader for the 
                // selected file
                FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fStream);

                // convert the file to a byte array
                byte[] data = br.ReadBytes((int)numBytes);
                br.Close();

                // pass the byte array (file) and file name to the web service
                //string sTmp=service1.UploadFile1()

                fStream.Close();
                fStream.Dispose();

                // this will always say OK unless an error occurs,
                // if an error occurs, the service returns the error message
                //MessageBox.Show("File Upload Status: " + sTmp, "File Upload");
            }
            else
            {
                // Display message if the file was too large to upload
                MessageBox.Show("The file selected exceeds the size limit for uploads.", "File Size");
            }
        }
        catch (Exception ex)
        {
            // display an error message to the user
            MessageBox.Show(ex.Message.ToString(), "Upload Error");
        }
    }
private void button1_Click(object sender, EventArgs e)
    {
        if (textBox1.Text != string.Empty)
           service1.UploadFile1(textBox1.Text);
        else

            MessageBox.Show("You must select a file first.", "No File Selected");
    }
    [WebMethod]
    public string UploadfileFinal(byte[] f, string fileName)
    {
        // the byte array argument contains the content of the file
        // the string argument contains the name and extension
        // of the file passed in the byte array
        try
        {
            // instance a memory stream and pass the
            // byte array to its constructor
            MemoryStream ms = new MemoryStream(f);

            // instance a filestream pointing to the 
            // storage folder, use the original file name
            // to name the resulting file
            FileStream fs = new FileStream
                (System.Web.Hosting.HostingEnvironment.MapPath("~/pic/") +
                fileName, FileMode.Create);

            // write the memory stream containing the original
            // file as a byte array to the filestream
            ms.WriteTo(fs);

            // clean up
            ms.Close();
            fs.Close();
            fs.Dispose();

            // return OK if we made it this far
            return "OK";
        }
        catch (Exception ex)
        {
            // return the error message if the operation fails
            return ex.Message.ToString();
        }
    }
...