English 中文(简体)
LINQ 没有提供储存档案的星号数据类型
原标题:LINQ doesn t provide a byte[] data type for storing files

I m试图在SQL服务器数据库中储存一个档案,并正在使用ASP。 NET MVC 3 with LINQ to in C#. 当我试图将一栏的数据类型按顺序排列时,它说,这是一种无效的数据类型。 采用数字数据类型似乎与逻辑上一样。

目的是将PDF文件储存在用户选择使用“吉大港山区”档案库上。 错误发生在RLINQ成员变量的转让期间,即档案储存的栏目。

不可逆转3 不可含蓄地转换类型系统。 Web.HttpPostedFileBase to System.Data.Linq。 Binary C:UsersAaron PattenDocuments 视觉演播室2010年项目

I haven t found much in the way of other people encountering this problem, so I think there must be something I m missing that is too elementary for anyone to post.

我的控制者:

    public ActionResult UploadPDF()
    {
        List<ViewDataUploadFilesResult> r = new List<ViewDataUploadFilesResult>();

        HttpPostedFileBase hpf;// = Request.Files[file] as HttpPostedFileBase;

        foreach (string file in Request.Files)
        {
            hpf = Request.Files[file] as HttpPostedFileBase;
            if (hpf.ContentLength == 0)
                continue;
            string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "images\" + Path.GetFileName(hpf.FileName));
            hpf.SaveAs(savedFileName);

            r.Add(new ViewDataUploadFilesResult()
            {
                Name = savedFileName,
                Length = hpf.ContentLength
            });
        }

        MyApp.Models.MyAppDataContext db = new MyApp.Models.MyAppDataContext();

        MyApp.Models.PDFFile myPDFFile = new MyApp.Models.PDFFile();

        myPDFFile.Content = hpf;
        db.questions.InsertOnSubmit(myPDFFile);
        db.SubmitChanges();

        return View("UploadPDF", r);
    }

怎样才能做到这一点?

P.S.:我如何把PDF作为嵌入物体,而不将其留给服务器?

D.A.P.

最佳回答

错误信息告诉你,什么是错的......你设置了内容。 hpf是HttpPoted 因此,它首先需要转换成一种方式。 是否通过从头到尾读。

myPDFFile.Content = new BinaryReader(hpf.InputStream).ReadBytes(hpf.InputStream.Length)

问题回答

In your LINQ to SQL entity designer change the field giving you trouble from System.Data.Linq.Binary to a type of System.Byte[]. The conversion will be implicit upon submission.

“entergraph





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签