0

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

在数据库中,我可以看到新的文件名和路径,但是当我转到应该保存新文件的实际文件夹时,它不存在。如果有人能指出我如何解决这个问题,那就太好了: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);
}
4

1 回答 1

0

我在我的一个项目中使用此代码:

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 保存在您的数据库中

于 2013-07-01T14:04:57.290 回答