简体   繁体   中英

Best way of moving a file from one network to another c# iis

I am writing an IIS Web service (in an asmx file) using C# that takes a file as an input and moves it to a specific server directory.

What I am currently doing is, I convert this file into a Base64 string before calling the web service, and pass this Base64 type string into the web service. Web service converts the string into a file and saves it to the directory.

Is there a better practice ?

As LB pointed out in the comments that;

Web services (hosted in .asmx) use xml/soap based protocol which means every binary data has to be converted to text (base64, hex string etc. ) either manually or automatically.

So the best way is what I was doing it from the beginning. Here is the codes that I use;

Converting a file into Base64 type string;

byte[] bytes = File.ReadAllBytes("file path");
string file = Convert.ToBase64String(bytes);

Converting Base64 string back into file;

byte[] bytes = Convert.FromBase64String(b64Str);
File.WriteAllBytes(path, bytes);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM