-3

I wanted to upload file using C# for which I need its Name, Type and size etc as an example given below. Please let me know, how can I do that.

[file2] => Array ( [name] => MyFile.jpg [type] => image/jpeg [tmp_name] => /tmp/php/php6hst32 [error] => UPLOAD_ERR_OK [size] => 98174 ) ) 

Here is my existing code:

private void choosFileBtn_Click(object sender, EventArgs e) { OpenFileDialog ofdChoos = new OpenFileDialog(); if (ofdChoos.ShowDialog() == DialogResult.OK) { System.Net.WebClient Client = new System.Net.WebClient(); // Client.Headers.Add("Content-Type", "binary/octet-stream"); var sourceString = ofdChoos.FileName.Replace(@"\", @"/"); var source = @"" + sourceString; var result = Client.UploadFile("https://zaffarology.com/upload.php", "POST", @source); string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); } } 
22
  • That code doesn't look like C#.. Commented Oct 11, 2018 at 12:55
  • What have you tried? where did you get stuck? what did you google? Commented Oct 11, 2018 at 12:55
  • That is PHP. Are you trying to say you want to upload to a php script from C#? Commented Oct 11, 2018 at 12:56
  • @Cory, Yea this is PHP, I need same thing in C# Commented Oct 11, 2018 at 12:57
  • 1
    The question you mentioned that no-one was replying to has two duplicates marked (1, 2), both of which have accepted answers which look useful at the very least. Commented Oct 11, 2018 at 13:05

1 Answer 1

0

I have solved problem myself. Thanks to all who replied me and tried their best to help. Really Appreciated!

Solution Code

OpenFileDialog ofdChoos = new OpenFileDialog(); if (ofdChoos.ShowDialog() == DialogResult.OK) { System.Net.WebClient Client = new System.Net.WebClient(); var sourceString = ofdChoos.FileName.Replace(@"\", @"/"); var source = @"" + sourceString; string exts = Path.GetExtension(source); string ext = exts.Replace(@".", string.Empty); Client.Headers.Add("Content-Type", ext); var result = Client.UploadFile("https://zff.com/upload.php", "POST", @source); string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); MessageBox.Show(s); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.