?
Solved

how to auto upload file through web in iis

Posted on 2001-07-14
10
Medium Priority
?
783 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 1200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

719 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