保存正在上载的文件的副本

本文关键字:文件 副本 上载 保存 | 更新日期: 2023-09-27 18:20:38

我有一个方法,可以上传一个文件,同时更改名称和路径,并将其副本保存到具有新名称的新路径。

在数据库中,我可以看到新的文件名和路径,但当我转到应该保存新文件的实际文件夹时,它不在那里。如果有人能指出我如何解决这个问题,那就太好了:D

static string docx = @"../../TestFiles/Types.docx";
try
{
    FileStream fileStream = new FileStream(docx, FileMode.Open, FileAccess.Read);
    string filePath = fileStream.Name;
    string fileName = Path.GetFileName(fileStream.Name);
    docConverter.FileSubmit(6, filePath, fileName, 1, FILESTORELOCATION, 89);
    fileStream.Close();
}
public void FileSubmit(int studentId, string rawStoragePath, string fileName, int uploadedByUserId, string storagePath, int assignmentElementsId)
{
    Guid strGUID = Guid.NewGuid();
    string FILESTORELOCATION = @"C:'TestFiles'";
    storagePath = FILESTORELOCATION + strGUID + ".pdf";
    DateTime uploadDate = DateTime.UtcNow;
    stuSubSvc.UploadAssignment(studentId, strGUID,fileName, rawStoragePath, uploadDate, uploadedByUserId, storagePath, 0, assignmentElementsId);
}

保存正在上载的文件的副本

我在我的一个项目中使用了这段代码:

string consPath = "C:''WEB''DirectiveFiles''";
private string FindExtension(string FileFullName)
{
    int lastDOT = FileFullName.LastIndexOf(".");
    string myFileExtension = FileFullName.Substring(lastDOT + 1);
    myFileExtension = myFileExtension.ToLower();
    if (myFileExtension != "jpg" && myFileExtension != "pdf" && myFileExtension != "gif" && myFileExtension != "zip")
        myFileExtension = "Error";
    return myFileExtension;
}
if (fileUp1.HasFile)
{
    fileExtension = FindExtension(fileUp1.FileName);
    if (fileExtension == "Error")
    {
        extFlag = true;
        lblUpError1.Visible = true;
        lblUpError1.Text = "Not Proper File " + fileUp1.FileName;
        goto continueWithoutUpload;
    }
    else
    {
        filePath1 = consPath + DocID + "." + fileExtension;
        fileUp1.SaveAs(consPath + fileUp1.FileName);
        File.Move(@consPath + fileUp1.FileName, @filePath1);
    }
}

并最终将filePath1保存在您的DB 中