我有一个问题是从数据库编辑上传文件 [英] I have a question to edit a upload file from database

查看:58
本文介绍了我有一个问题是从数据库编辑上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个代码来上传数据库中的pdf文件,现在我想编辑上传加载的文件,在此期间发生错误...任何人都可以告诉如何删除此错误

此行中的错误





FileUpload1.PostedFile.FileName = dt.Rows [0] [SelectedFile]。ToString( );

I have write a code to upload the pdf file in the database and now i want to edit the upload loaded file during this an error occur ...any one can tell how to remove this error
the error in this line


FileUpload1.PostedFile.FileName= dt.Rows[0]["SelectedFile"].ToString();

推荐答案

FileName是只读属性。您正在尝试将名称设置为fileupload控件的FileName属性,这是不可能的。因此该行将抛出编译时错误。

其次,您无法以这种方式编辑提交的文件。如果你想编辑(文件名),删除你已经上传的文件,你可以更好地使用主ID。

例如:

你可以存储使用2种方法的文件:

1]您可以使用主ID将字节存储到表中,而不是使用主ID,您可以更改该文件名或删除字节。

2]您还可以保存文件路径而不是字节,并使用相同的ID物理存储文件。因此,您可以使用File类在sql表中以及在文件系统(上载实际文件的位置)中使用主ID进行编辑或删除。



两种方法都有优点和缺点,但从性能的角度来看,第二种方法总是更可取。



谢谢,

Suraj
FileName is read only property. You are trying to set the name to the FileName property of fileupload control which is not possible. So that line will throw an compile time error.
Secondly, you can not edit submitted file in this way. If you want to edit (name of file),delete file which you have already uploaded, better you can use primary ID for that.
for example :
you can store files using 2 methods :
1] you can store bytes into the table with primary ID than by using primary ID you can change that file name or delete bytes.
2] you can also save the file path instead of bytes and store file physically using same id. so you can edit or delete using primary ID in sql table and also in file system (where you actual file is uploaded) using File class.

Both methods have there advantages and disadvantages but from the performance point of view second method is always preferable.

Thanks,
Suraj


这篇关于我有一个问题是从数据库编辑上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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