Solved

how to auto upload file through web in iis

Posted on 2001-07-14
10
777 Views
Last Modified: 2010-04-06
<form action=/script/uploadfile.asp ENCTYPE="multipart/form-data"
           METHOD=POST>
<input type=file name="filename">
</form>
I want to set file value by programing instead of manual selection.
but the inputfileelement.value is readonly
0
Comment
Question by:gutian
[X]
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
  • 6
  • 4
10 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6282196
It's read-only for security reasons...
0
 

Author Comment

by:gutian
ID: 6282368
I know it is read-only for reason ,I just want to know do it by any ways.
If I post the file with Sendrequestex,how can I do .
Thanks
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6282431
Try the http component of the Indy's:

http://www.nevrona.com/Indy/Download.html
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Accepted Solution

by:
Epsylon earned 300 total points
ID: 6282494
Then tru this:


procedure TForm1.Button1Click(Sender: TObject);
var
  Request       : TMemoryStream;
  FileData      : TMemoryStream;
  Response      : TStringStream;
  tempArray     : array[0..10000] of char;
  tempString    : String;
  strFileSize   : String;
  InFile        : String;
const
  NewLine = chr(13) + chr(10);
begin
  Screen.Cursor := crHourGlass;

  InFile := 'c:\test.zip';

  // Set the properties for HTTP
  HTTP.ProtocolVersion                := pv1_1;
  HTTP.Request.Username               := '';
  HTTP.Request.Password               := '';
  HTTP.Request.ProxyServer            := '';
  HTTP.Request.ProxyPort              := 80;
  http.Request.ContentEncoding        := 'multipart/form-data';

  try

    // create streams
    Response  := TStringStream.Create('');
    Request   := TMemoryStream.Create;
    FileData  := TMemoryStream.Create;

    // load file data
    FileData.LoadFromFile( InFile );
    FileData.Seek( 0, soFromBeginning );
    // copy form data
    TempString := '';
    TempString := TempString + '-----------------------------7d18914904ee' + NewLine;
    TempString := TempString + 'Content-Disposition: form-data; name="UserName"' + NewLine;
    TempString := TempString + '' + NewLine;
    TempString := TempString + edUserName.text + NewLine;
    TempString := TempString + '-----------------------------7d18914904ee' + NewLine;
    TempString := TempString + 'Content-Disposition: form-data; name="PassWord"' + NewLine;
    TempString := TempString + '' + NewLine;
    TempString := TempString + edPassWord.text + NewLine;
    TempString := TempString + '-----------------------------7d18914904ee' + NewLine;
    TempString := TempString + 'Content-Disposition: form-data; name="FileSize"' + NewLine;
    TempString := TempString + '' + NewLine;
    TempString := TempString + '1234567' + NewLine;
    TempString := TempString + '-----------------------------7d18914904ee' + NewLine;
    TempString := TempString + 'Content-Disposition: form-data; name="DataFileName"; filename="' + InFile + '"' + NewLine;
    TempString := TempString + 'Content-Type: application/octet-stream' + NewLine;
    TempString := TempString + '' + NewLine;

    // Add data to post
    FillChar( temparray, SizeOf( temparray ), #0 );
    strpcopy( temparray, tempstring );
    Request.Write( temparray, length(tempstring) );
    Request.Seek( 0, soFromEnd );
    Request.CopyFrom( FileData, FileData.Size );

    // copy form data
    TempString := '';
    TempString := TempString + '' + NewLine;
    TempString := TempString + '-----------------------------7d18914904ee' + NewLine;
    TempString := TempString + 'Content-Disposition: form-data; name="Submit"' + NewLine;
    TempString := TempString + '' + NewLine;
    TempString := TempString + 'Submit' + NewLine;
    TempString := TempString + '-----------------------------7d18914904ee--'  + NewLine;
    // Add data to post
    FillChar( temparray, SizeOf( temparray ), #0 );
    strpcopy( temparray, tempstring );
    Request.Write( temparray, length(tempstring) );

    // post file
    try
      HTTP.Post( edUrl.Text, Request, Response);
    except
      showmessage( "Failed!")
    end;

    // write out debug text
    memo1.lines.Add('===[TForm1.Post - Response.DataString]=================');
    memo1.Lines.add( Response.DataString );

  finally
    Response.Free;
    Request.Free;
    FileData.Free;
    Screen.Cursor := crDefault;
  end;
end;
0
 

Author Comment

by:gutian
ID: 6283535
thanks.BTW I want to build it in a dlls,how can I do.
I have build a dlls,but when I close main form,an error
show
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6283555
What error? Closing the main form of the DLL?
Showing some code could help...
0
 

Author Comment

by:gutian
ID: 6283970
function PostData(hHandle:THandle;vUrl,vFileName,SavePath:string):Boolean;external 'uprequest.dll'

this is the call
if PostData(application.Handle,Url,Filename,Path) then
    showmessage('very good');

when I close the main form ,it tell me
project ..\dlls\dllcall,exe raised too many consecutive execptions:'access violation at 0x343343:read of address 0x00ea25f0'.process stopped use step or run to continue
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6284951
Do you know about the limitation when using strings as parameter in dll functions?

  Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters.


I don't know if this is causing the exceptions. I need more info...
0
 

Author Comment

by:gutian
ID: 6286053
thanks for your kind help,I have resoled the problem.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6286767
Alright then. Thanks for the points.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

617 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