473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C# and VC6 Web Services File Upload

I'm cross posting, sorry, but this pertains to both sides..

I have a Web Services written in C# and a client written in VC6. I've
never uploaded files through web services so forgive my ignorance in this
matter, but I'm trying to understand how I can do this from the C++ client.

The C# code works for HTTP Form Posts, but not really what I'm looking for..
This should be for applications to upload files too.. The code is as
follows:
-----------------------------------------------------------------
[WebMethod]
public bool UploadFileCollection()
{
try
{
//HTTP Context to get access to the submitted data
HttpContext postedContext = HttpContext.Current;

//File Collection that was submitted with posted data
HttpFileCollection Files = postedContext.Request.Files;

//Make sure a file was posted
//This works for HTTP Form Posts, need to understand how to make this
work for C++ posts
string fileName = (string)postedContext.Request.Form["fileName"];

if (Files.Count == 1 && Files[0].ContentLength 1 && fileName != null
&& fileName != "")
{
//The byte array we'll use to write the file with
byte[] binaryWriteArray = new
byte[Files[0].InputStream.Length];
//Read in the file from the InputStream
Files[0].InputStream.Read(binaryWriteArray, 0,
(int)Files[0].InputStream.Length);
//Open the file stream
FileStream objfilestream = new FileStream("c:\\" + fileName,
FileMode.Create, FileAccess.ReadWrite);
//Write the file and close it
objfilestream.Write(binaryWriteArray, 0,
binaryWriteArray.Length);
objfilestream.Close();
return true;
}
else
{
return false;
}
}
catch (Exception ex1)
{
throw new Exception("Problem uploading file: " + ex1.Message);
}
}

-----------------------------------------------------------------
I have VC6 client that is to upload a file to the C# Web Services Interface
using WinHttp..
WinHttpOpen
WinHttpConnect
WinHttpOpenRequest
WinHttpSetOption
WinHttpAddRequestHeaders
WinHttpWriteData //header
WinHttpWriteData //binary file in data chunks
WinHttpWriteData //footer
WinHttpReceiveResponse
WinHttpQueryHeaders
WinHttpQueryDataAvailable
WinHttpReadData
WinHttpCloseHandle

I've never written anything in C++ to talk to Web Services before and I know
this code work for file uploads to IIS via ASPUpload object on the server.
I may be way off, but my searching is leading me no where.
Apr 1 '08 #1
5 2361
Can't you accept two parameters like so?
public void UploadFile(string fileName, byte[] fileData)
Or is that bad practise for some reason I am unaware of?
Pete
Apr 1 '08 #2
Problem with two params, is now, I step out of the application post binary
to a website as we do today using ASPUpload object on the server. I really
don't want to change our client process, since it's rock solid, but was
willing to tweak it if necessary. However Marc Gravell's suggestion on
the Web Services side I'm going to try.. The web services part is all new
and I can handle it most anyway I want.

"Peter Morris" <peter[dot]morris(at)capableobjects.comwrote in message
news:um**************@TK2MSFTNGP02.phx.gbl...
Can't you accept two parameters like so?
public void UploadFile(string fileName, byte[] fileData)
Or is that bad practise for some reason I am unaware of?
Pete

Apr 1 '08 #3
If all else fails, try using a handler that uses your existing Files
etc code via the context.Request; I suspect that asmx isn't doing
anything for you if you are using ASPUpload etc. It simply isn't the
same type of service.

Marc
Apr 2 '08 #4
My only thought is that there are better ways of copying streams -
i.e. so that you don't need to read it all into memory first.
An example is given here:

http://groups.google.co.uk/group/mic...757ed972e54ce7

Marc
Apr 3 '08 #5
(I should have said - the stress is on CopyStream - you can ignore the
GZip stuff...)
Apr 3 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
3
by: david | last post by:
For example, there is a text file myText.txt in the web server with path /myData/ How to write the service and the window form client? Thanks David
4
by: Craig HB | last post by:
I have an Access 2002 database that uploads data into a SQL Server 2000 database using DTS. Each upload includes 5 tables of up to 1000 rows. This is a weekly upload that takes place in about 250...
2
by: Justin Lazanowski | last post by:
I have a windows app that I am writting for some field reps. This app should download and upload specific information to a web service, and cache the information on the local computer when they are...
4
by: AtulSureka | last post by:
Hi, I have file of relatively larger size (4-5 Mbs) on client machine. I want to send this file to Server. For this I am using web services. Following is my perception, Please correct me if I...
6
by: David++ | last post by:
Dear List, If I develop a Web Service in C# and upload it to my .NET server it is then very easy to use the Web Service in a .NET programmed client (i.e. C# win forms) by simply using 'Add Web...
6
Jacotheron
by: Jacotheron | last post by:
I need a PHP script that can upload music files (mp3). The script is for a home project I have started a while ago. I have a MySQL database of all the music that I have. Other computers on the...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.