Solved

C# console application question need help with public string Main

Posted on 2007-08-03
4
492 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
Comment Utility
I don't understand your problem:

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

Bob
0
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
Comment Utility
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
Comment Utility
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 62

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Idea or tool for building a form application using ASP.net MVC 2 27
Editing XSL files, 2 18
Expando 4 33
ASP.NET reading ATOM 2 20
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now