在此方法中最后保存文件路径后,我必须复制相同的文件,我需要移动到另一个地方,我需要将该文件作为RAR文件如何做到这一点?
public JsonResult UploadResume(HttpPostedFileBase resume)
{
if (resume != null)
{
string Name = System.IO.Path.GetFileName(resume.FileName);
string path = Server.MapPath("~/Uploads/Resume/0");
string extension = Path.GetExtension(resume.FileName);
DirectoryInfo di = null;
if (!Directory.Exists(path))
{
di = Directory.CreateDirectory(path);
}
var filepath = System.IO.Path.Combine(path, 0 + extension);
resume.SaveAs(filepath);
}
return Json(new { result = true }, JsonRequestBehavior.AllowGet);
}
答案 0 :(得分:1)
试试这个
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string sFileToZip = @"C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\ConsoleApplication1\bin\Debug\Stuff\text1.txt";
string sZipFile = @"C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\ConsoleApplication1\bin\Debug\Stuff\text1.zip";
using (FileStream __fStream = File.Open(sZipFile, FileMode.Create))
{
GZipStream obj = new GZipStream(__fStream, CompressionMode.Compress);
byte[] bt = File.ReadAllBytes(sFileToZip);
obj.Write(bt, 0, bt.Length);
obj.Close();
obj.Dispose();
}
}
}
}
答案 1 :(得分:0)
您需要使用某种第三方库将文件压缩为RAR格式,或者执行命令行工具(如RAR.EXE)来执行此操作。
答案 2 :(得分:0)