c# - FileUpload file cleared after uploading it with ftp -



c# - FileUpload file cleared after uploading it with ftp -

i'm having problem processing uploaded file after has been uploaded ftp.

the file user uploads contains xml. have save file disk i'm not able write file straight disk utilize ftp save it. after saved needs processed save contents in database. xmlreader fails error "no root element detected". after debugging came conclusion file empty.

i tried re-create file (where xsdupload file uploaded user):

fileupload test = new fileupload(); test = xsdupload;

but i'm not shure if copys file in memory.

the ftp upload function followed:

public string uploadxsd(string filename, fileupload xsd) { ftpwebrequest request = (ftpwebrequest)webrequest.create(url + '/' + filename); request.method = webrequestmethods.ftp.uploadfile; request.credentials = new networkcredential(username, password); streamreader sourcestream = new streamreader(xsd.filecontent); byte[] filecontents = encoding.utf8.getbytes(sourcestream.readtoend()); sourcestream.close(); request.contentlength = filecontents.length; stream requeststream = request.getrequeststream(); requeststream.write(filecontents, 0, filecontents.length); requeststream.close(); ftpwebresponse response = (ftpwebresponse)request.getresponse(); response.close(); homecoming url + '/' + filename; }

this function works fine. can see file in directory supposed be.

to process file use:

xmlreader reader = xmlreader.create(xsduploaded.filecontent); while (reader.read()) { if (reader.name != "") {

does have solution?

it seems filecontent property stream class instance , should seek origin before sec reading, i.e.

xsduploaded.filecontent.seek(0, seekorigin.begin); xmlreader reader = xmlreader.create(xsduploaded.filecontent);

i not sure, hope helps.

best regards.

c# asp.net file-upload ftp

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -