C# 多文件上传并将其转换为html格式

C# 多文件上传并将其转换为html格式,c#,asp.net,C#,Asp.net,我试图上传多个文件,并通过将它们放入for循环,将它们同时转换为.html格式。多个文件上载完成并存储到“上载”文件中,但只有第一个文件转换为.htm格式,而不是全部 这是我的密码: protected void btnUpload_Click(object sender, EventArgs e) { HttpFileCollection fileCollection = Request.Files; //Code to check if user h

我试图上传多个文件,并通过将它们放入for循环,将它们同时转换为
.html
格式。多个文件上载完成并存储到“上载”文件中,但只有第一个文件转换为
.htm
格式,而不是全部

这是我的密码:

protected void btnUpload_Click(object sender, EventArgs e)
    {

        HttpFileCollection fileCollection = Request.Files;
        //Code to check if user has selected any file on the form
        if (!(fUpload1.HasFile))
        {
            lblMessage1.Text = "Please choose file to upload";
        }
        else
        {
            for (int i = 0; i < fileCollection.Count; i++)
            {
                try
                {
                    HttpPostedFile uploadfile = fileCollection[i];
                    string fileName = System.IO.Path.GetFileName(uploadfile.FileName);

                    //To check the file extension if it is word document or something else
                    //string strFileName = fUpload1.FileName;
                    string[] strSep = fileName.Split('.');
                    int arrLength = strSep.Length - 1;
                    string strExt = strSep[arrLength].ToString().ToUpper();

                    //Save the uploaded file to the folder
                    strPathToUpload = Server.MapPath("Uploaded2");

                    //Map-path to the folder where html to be saved
                    strPathToConvert = Server.MapPath("Aadi2");

                    object FileName = strPathToUpload + "\\" + fileName;
                    object FileToSave = strPathToConvert + "\\" + fileName + ".htm";

                    if (strExt.ToUpper().Equals("DOC") | strExt.ToUpper().Equals("DOCX"))
                    {
                        uploadfile.SaveAs(strPathToUpload + "\\" + fileName);
                        lblMessage1.Text = "File uploaded successfully";
                        //open the file internally in word. In the method all the parameters should be passed by object reference
                        objWord.Documents.Open(ref FileName, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing, ref missing);
                        //Do the background activity
                        objWord.Visible = false;


                        Microsoft.Office.Interop.Word.Document oDoc = objWord.ActiveDocument;
                        oDoc.SaveAs(ref FileToSave, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                        lblMessage1.Text = fileName + " done";

                    }
                    else if (strExt.ToUpper().Equals("JPG"))
                    {
                        strPathToUpload = Server.MapPath("images");
                        uploadfile.SaveAs(strPathToUpload + "\\" + fUpload1.FileName);
                        lblMessage1.Text = "logo uploaded successfully";

                    }
                    else if (strExt.ToUpper().Equals("TXT"))
                    {
                        strPathToUpload = Server.MapPath("name");
                        fUpload1.SaveAs(strPathToUpload + "\\" + fUpload1.FileName);
                        lblMessage1.Text = "Website name uploaded successfully";

                    }
                    else if (strExt.ToUpper().Equals("MP4"))
                    {
                        strPathToUpload = Server.MapPath("video");
                        fUpload1.SaveAs(strPathToUpload + "\\" + fUpload1.FileName);
                        lblMessage1.Text = "Video uploaded successfully";

                    }

                    else
                    {
                        lblMessage1.Text = "Invalid file selected!";
                    }
                    //Close/quit word
                    objWord.Quit(ref missing, ref missing, ref missing);
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
        }
    } 
protectedvoidbtnupload\u单击(对象发送方,事件参数e)
{
HttpFileCollection fileCollection=Request.Files;
//用于检查用户是否在表单上选择了任何文件的代码
如果(!(fUpload1.HasFile))
{
lblMessage1.Text=“请选择要上传的文件”;
}
其他的
{
for(int i=0;i
您不能使用asp.net中的一个文件上载控件上载多个文件

请检查此处以获取解决方案: 及


或者,要上载多个文件,您可以在客户端生成多个上载控件或创建用户定义的控件。

您正在使用Interop转换文档文件-,这就是


您可以使用其他库,如(免费)或(商业),这些库不依赖Office,并且在您的服务器场景中完全受支持。

如果目录中存在上载的文件,则使用directory.GetFiles代替httpfilecollection。它将从目录中返回案例中的特定文件*.doc文件,然后将其转换为.html

string[] filePaths = Directory.GetFiles(@"d:\files\", "*.doc");

我是c#的初学者。。。所以,如果你能指出我在代码中犯了什么错误的话..上传成功并存储在文件夹“Upload”中.但是只有第一个文档文件被转换成.htm格式谢谢..我会调查的