Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

C# console application question need help with public string Main

Posted on 2007-08-03
4
498 Views
Last Modified: 2013-11-07
How would I add the fileupload to the public static main to be able to run this console application



using System;

using System.Collections.Generic;

using System.Text;

using System.Net;

using System.Security.Cryptography.X509Certificates;

using System.IO;

namespace simpleDTpost

{

class httpPost

{

public static void Main(string[] args)

{

}

static void FileUpload()

{

string dataBoundary = "------------------------------7d2e2c76e104be--";

CookieContainer cookies = new CookieContainer();

string uri = ("https://www.qa.dealertrack.com/DealerFeed/Dealerfileupload.asp");

string filename = (@"Z:\ZQ1412JPM\dealers.csv");

string user = "xxxxxx";

string passwd = "xxxxxx";

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);

req.Credentials = new NetworkCredential(user, passwd);

req.CookieContainer = cookies;

X509Certificate x509 = X509Certificate.CreateFromCertFile(@"C:\Documents and Settings\rbreault\Desktop\qa.dt.cer");

req.ClientCertificates.Add(x509);

req.ContentType = "multipart/form-data; boundary=---------------------------7d2e2c76e104be Accept-Encoding: gzip, deflate -----------------------------7d2e2c76e104be";

req.Method = "POST";

byte[] fileData = File.ReadAllBytes(filename);

string fileStr = Convert.ToBase64String(fileData);

StringBuilder dataString = new StringBuilder();

StringBuilder dataString2 = new StringBuilder();

dataString.Append(dataBoundary + "\r\n");

dataString.Append("Content-Disposition: form-data; name=\"FILE\"; filename=\"file.csv\"\r\n");

dataString.Append("Content-Type: Application/octet-stream\r\n\r\n");

byte[] tmpPostData = System.Text.Encoding.Default.GetBytes(dataString.ToString());

byte[] t = new byte[tmpPostData.Length + fileData.Length];

tmpPostData.CopyTo(t, 0);

fileData.CopyTo(t,tmpPostData.Length);

string tmp = System.Text.Encoding.Default.GetString(t);

req.ContentLength = t.Length;

Stream tempStream = req.GetRequestStream();

// Write the data to be posted to the request stream

tempStream.Write(t, 0, t.Length);

tempStream.Close();

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Read the raw HTML from the request

StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.Default);

// Convert the stream to a string

string s = sr.ReadToEnd();

sr.Close();

resp.Close();

Console.WriteLine(s);


}

}

}





Thanks in advance
0
Comment
Question by:jareddraper
  • 2
4 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 19626508
I don't understand your problem:

public static void Main(string[] args)
{
   FileUpload();
}

Bob
0
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 19626556
Hi jareddraper;

Hope that this is what you are looking for.

public static void Main(string[] args)
{

    FileUpload();
    // So that the Console window does not go away after the function is run
    // place a console readline to stop the program from terminating.
    Console.Readline();

}

Fernando
0
 

Author Comment

by:jareddraper
ID: 19626645
Thank you so much sorry for the dumb question.... I am going to split the points since you both answered the question but FernandoSoto added a extra line for me. I am trying to be fair hope that doesn't bother either of you.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 19628375
Not a problem, Always glad to help. ;=)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question