如何使用在线数据库使用C#应用程序上传服务器中的简历 [英] how to upload resume in server using C# application using online database

查看:44
本文介绍了如何使用在线数据库使用C#应用程序上传服务器中的简历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#应用程序使用在线数据库上传简历

how to upload resume in server using C# application using online database

推荐答案

TS提到'resume'。在上传和成功存储文件之前发布的解决方案,但不支持恢复方案。



为了支持简历,请进行以下更改:



- 检查文件名的记录是否已经存在

- 将现有二进制数据的长度作为起点,或将长度存储在单独的出于性能原因的字段

- 使用循环从起点读取文件内容

- 附加到现有数据并在循环数据库中更新它



这样,每当上传/取消上传时,已处理的块将始终存储在数据库中。



另外,我会在表格中添加一个标记,表明上传是否已完成,或者记录是否包含上传文件中的部分数据。



如果您需要代码示例,请告诉我。
TS mentioned 'resume'. The solution posted before uploads and stores the file successfully, but does not support a resume scenario.

In order to support resume, make the following changes:

- Check if a record for the filename already exists
- Take the length of the existing binary data as starting point, or store the length in a separate field for performance reasons
- Read the file contents from the starting point using a loop
- Append to the existing data and update it in the database in the loop

This way, whenever the upload is aborted/cancelled, the chunks that were already processed will always be stored in the database.

In addition, I would add a flag to the table to indicate if the upload has completed or if the record contains partial data from the uploaded file.

If you need a code sample, let me know.


protected void btnUpload_Click(object sender, EventArgs e)
{
    // Read the file and convert it to Byte Array
    string filePath = FileUpload1.PostedFile.FileName;  
    string filename = Path.GetFileName(filePath);
    string ext = Path.GetExtension(filename);
    string contenttype = String.Empty;
 
    //Set the contenttype based on File Extension
    switch(ext)
    {
        case ".doc":
            contenttype = "application/vnd.ms-word";
            break;
        case ".docx":
            contenttype = "application/vnd.ms-word";
            break;        
        case ".pdf":
            contenttype = "application/pdf";
            break;
    }
    if (contenttype != String.Empty)
    {
 
        Stream fs = FileUpload1.PostedFile.InputStream;
        BinaryReader br = new BinaryReader(fs);
        Byte[] bytes = br.ReadBytes((Int32)fs.Length);
 
        //insert the file into database
        string strQuery = "insert into tblFiles(Name, ContentType, Data)" +
           " values (@Name, @ContentType, @Data)";
        SqlCommand cmd = new SqlCommand(strQuery);
        cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename;
        cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value
          = contenttype;
        cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
        InsertUpdateData(cmd);
        lblMessage.ForeColor = System.Drawing.Color.Green;  
        lblMessage.Text = "File Uploaded Successfully";
    }
    else
    {
        lblMessage.ForeColor = System.Drawing.Color.Red;   
        lblMessage.Text = "File format not recognised." +
          " Upload Image/Word/PDF formats";
    }
}


这篇关于如何使用在线数据库使用C#应用程序上传服务器中的简历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆