C#中调用EXT文件

分类:  C#2009-03-04 16:56  130人阅读  评论(0)  收藏  举报

1. 如果exe文件的返回值是int类型,标识操作执行的结果是否成功,例如:

class Program

    {

        static int Main(string[] args)

        {

            return args.Length;

        }

 }

则在调用exe文件时,可以用如下方法:

Process myProcess = new Process();

string fileName = @"C:/Test.exe";

string para =@"你好 北京欢迎你!";

ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(fileName, para);

myProcess.StartInfo = myProcessStartInfo;

myProcess.Start();

while (!myProcess.HasExited)

{

   myProcess.WaitForExit();

}

int returnValue = myProcess.ExitCode;

 

2. 如果exe文件是将输出内容写入标准流,例如:

class Program

    {

        static void Main(string[] args)

        {

            Console.Write(args[0] + args[1] + args [2]);           

        }

 }

则在调用exe文件时,可以用如下方法:

string fileName = @"C:/Test.exe";

Process p = new Process();

p.StartInfo.UseShellExecute = false;

p.StartInfo.RedirectStandardOutput = true;

p.StartInfo.FileName = fileName;

p.StartInfo.CreateNoWindow = true;

p.StartInfo.Arguments = "你好, 北京 欢迎你!";//参数以空格分隔,如果某个参数为空,可以传入””

p.Start();

p.WaitForExit();

string output = p.StandardOutput.ReadToEnd();

C#中,使用千帆AppBuilder上传文件通常涉及以下步骤: 1. 首先,确保你已经获得了API客户端和访问令牌。AppBuilder通常会提供相关的文档指导如何获取这些认证信息。 2. 引入必要的NuGet包:如果你使用的是.NET框架,可能会需要`HttpClient`来进行HTTP请求。例如: ```csharp using System.Net.Http; ``` 3. 创建HttpClient实例,并设置基本授权头: ```csharp HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "your_access_token"); ``` 4. 构造文件数据: - 如果文件是一个流(Stream),可以这样做: ```csharp MultipartFormDataContent formData = new MultipartFormDataContent(); Stream fileStream = ...; // 获取文件流 HttpContent content = new StreamContent(fileStream); content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream"); formData.Add(content, "file", Path.GetFileName(fileStream.Name)); ``` - 如果文件是内存中的二进制内容,可以使用ByteArrayContent: ```csharp byte[] fileBytes = ...; // 文件字节数组 HttpContent content = new ByteArrayContent(fileBytes); content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream"); formData.Add(content, "file", "filename.ext"); ``` 5. 发送POST请求到AppBuilder的文件上传端点: ```csharp string apiUrl = "https://api.your-appbuilder.com/files/upload"; HttpResponseMessage response = await httpClient.PostAsync(apiUrl, formData); response.EnsureSuccessStatusCode(); ``` 6. 检查响应并处理上传结果: ```csharp string uploadIdOrUrl = await response.Content.ReadAsStringAsync(); // 获取上传后的URL或ID ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值