Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Valums uploader和DB在多个文件上保存_C#_Asp.net - Fatal编程技术网

C# Valums uploader和DB在多个文件上保存

C# Valums uploader和DB在多个文件上保存,c#,asp.net,C#,Asp.net,我正在使用valums uploader和我找到的一个ashx文件示例&tweeked,并希望在我上传时将每个文件中的数据保存到db中,单步执行代码,似乎没有任何方法来区分哪个文件是按哪个顺序上传的,观察某个变量,代码会跳得到处都是。对于单个文件,它可以正常工作,但超过1个是一个问题。此外,context.Request.Files.Count始终为0 byte[] buffer = new byte[request.ContentLength];

我正在使用valums uploader和我找到的一个ashx文件示例&tweeked,并希望在我上传时将每个文件中的数据保存到db中,单步执行代码,似乎没有任何方法来区分哪个文件是按哪个顺序上传的,观察某个变量,代码会跳得到处都是。对于单个文件,它可以正常工作,但超过1个是一个问题。此外,context.Request.Files.Count始终为0

            byte[] buffer = new byte[request.ContentLength];

            fileName = request.RawUrl.Split('=')[1];
            fmt = Path.GetExtension(fileName);

            using (BinaryReader br = new BinaryReader(request.InputStream)) 
            br.Read(buffer, 0, buffer.Length);

            File.WriteAllBytes(StorageRoot + request["qqfile"], buffer);

            success = false;
            context.Response.Write("{success:true}");
            HttpContext.Current.ApplicationInstance.CompleteRequest();

有什么想法吗?

我使用了valums uploader,没有问题。不同的浏览器以不同的方式上传文件。IE将使用一个文件上传html控件,而Firefox和Chrome可以使用Ajax风格。我编写了自己的上传处理程序,但您需要做的第一件事是确定使用了哪种方法

我是这样做的:

if (HttpContext.Current.Request.QueryString["qqfile"] != null)
    file = new UploadedFileXhr();
else if (HttpContext.Current.Request.Files.Count > 0)
    file = new UploadedFileForm();
else
    return new UploadResult("Request was not valid.");
XHR上载意味着您可以从输入缓冲区读取,如下所示:

int read = HttpContext.Current.Request.InputStream.Read(buffer, 0, buffer.Length);

while (read == buffer.Length)
{
    ms.Write(buffer, 0, buffer.Length);
    read = HttpContext.Current.Request.InputStream.Read(buffer, 0, buffer.Length);
}

ms.Write(buffer, 0, read);
UploadResult result = new UploadResult(true);
result.Stream = _File.InputStream;
result.Name = System.IO.Path.GetFileName(_File.FileName);
文件上载比较简单,如下所示:

int read = HttpContext.Current.Request.InputStream.Read(buffer, 0, buffer.Length);

while (read == buffer.Length)
{
    ms.Write(buffer, 0, buffer.Length);
    read = HttpContext.Current.Request.InputStream.Read(buffer, 0, buffer.Length);
}

ms.Write(buffer, 0, read);
UploadResult result = new UploadResult(true);
result.Stream = _File.InputStream;
result.Name = System.IO.Path.GetFileName(_File.FileName);

即使您在客户端中添加多个文件,每个文件都会单独上载。

非常好,在我开始浏览器测试时可能会派上用场,因为现在我将maxConnections设置为1,这很好地完成了任务