C#/网:返回一个文件浏览器?浏览器、文件

2023-09-04 02:55:38 作者:余墨残香独自敛

随着this问题它是建议我应该创建一个服务器端的文件,该文件可以从文件系统恢复文件。我会如何在C#和.NET这样做。我想我通过文件名作为查询字符串,这是由网页读取和文件恢复。真的不知道从哪里开始对这个从作弄点。

Following this question it was recommend that I should create a server side file that can return a file from the file system. How would I go about doing this in c# and .net. I imagine I pass the filename as a query string, this is read by the page and the file returned. Not really sure where to start on this from a codding point.

推荐答案

您可以使用Response.WriteFile方法来发送文件的内容,虽然这可能会失败,更大的文件。

You can use the Response.WriteFile method to send the contents of the file, though this may fail with larger files.

要小心,不要让任何文件名在查询字符串中指定,因为用户可以再使用该访问服务器上的任意文件。最好是有被允许与各1名的文件的数据库,并期待在查询字符串提供对这个数据库来获取文件名的名称。

Be careful not to allow any filename to be specified in your query string, as users could then use this to access any file on your server. Better to have a database of files that are allowed with a name for each one, and look up a name supplied in the query string against this database to get the filename.