I figured it out, thought I would post some sample code in case anyone
else is looking:
FYI: The code needs work before being "production " ready. I do not
believe this will work for some types of files, such as images, because it
would need to be changed to a base64 binary read. But I do not have this
need, I needed to read in standard text files.
[WebMethod]
public string GetData()
{
string theReturn = "";
StringBuilder sbOutput = new StringBuilder() ;
try
{
// the constructor for the http context
HttpContext theContext = HttpContext.Cur rent;
// file collection of uploaded files in the http context
HttpFileCollect ion Files = theContext.Requ est.Files;
// if something there then read the posted upload
if(1==Files.Cou nt & 1<Files[0].ContentLength)
{
theReturn += Files[0].ContentLength;
theReturn += Files[0].ContentType;
using(StreamRea der srFiledata = new StreamReader(Fi les[0].InputStream))
{
sbOutput.Append (srFiledata.Rea dToEnd());
}
// double check to make sure this is valid upload
// to do code
theReturn+=sbOu tput.ToString() ;
// now pick up the additional form fields
theReturn += theContext.Requ est.Form["dbConnecti on"];
//theReturn += theContext.Requ est.Form[2];
}
// here send back something to indicate that nothing was uploaded or it
is invalid
else
{
theReturn += "Nothing Uploaded";
}
}
catch(Exception ex1)
{
theReturn = ex1.Message;
}
return theReturn;
}
"Scanner200 1" <je************ @hotmail.com> wrote in message
news:O1******** ******@TK2MSFTN GP09.phx.gbl...
I am trying to receive form data posted from an html page to a web
service method. In other words, a web page posts data as
encrypt=multipa rt/form-data, the action is the webservice method, i.e.
action=webservi ce/methodname. The form includes the contents of an
uploaded file, i.e. a file browse button in the form.
I can perform similar actions taking in just string data and post it
to the web service and process the data. But I seem to be having a problem
with the uploaded file from the form.
Any suggestions on how to do this, or how to receive the data? I can
not modify the original html page that has the form, other than the url in the
action of the form.
Thanks,
J