C#Sql Excel上传 [英] C# Sql Excel Upload

查看:65
本文介绍了C#Sql Excel上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
以下链接是将excel记录上传到mssql服务器的代码。





http://www.codeproject.com/script/Membership/View.aspx?mid=5170372 [ ^ ]



这里要上传的excel文件将保存在程序文件夹中。



我需要进行一些小改动,用户可以选择使用FILEUPLOADER从他们的位置选择文件。



那么如何将File uploader与此代码结合起来。



由Vivekananda先生代码项目提供的代码..



请帮助我,我的项目< br $> b $ b

Ankit

ankitjpk@gmail.com

Hi The below link is the code of uploading excel record to mssql server.


http://www.codeproject.com/script/Membership/View.aspx?mid=5170372[^]

Here the excel file which is to be upload are to be saved in the program folder.

I need a small alteration , that to give a choice to the user to choose the file from their location using FILEUPLOADER.

So how can i combine File uploader with this code.

The code as been ontained from code project by Mr Vivekananda..

Please help me out , its my project

Ankit
ankitjpk@gmail.com

推荐答案

使用文件上传控制你需要2事情:

1.文件上传控件本身(很明显)。

2.用于触发文件上传的按钮控件。



所以你可以说:

To use File Upload Control you need 2 things:
1. The File Upload control itself (that's obvious).
2. A button control to trigger the file upload.

so you'll have let's say:
<asp:fileupload id="fileupload1" runat="server" xmlns:asp="#unknown" />



以及旁边的按钮:


and also a button right next to it:

<asp:button id="btnUpload" text="upload" runat="server" xmlns:asp="#unknown" />





您需要添加点击活动按钮实际上是要发布文件。

让我们假设你已经这样做了,C#已经有了点击前夕NT。然后你必须写一些像





You'll need to add a "On Click" event to the button to actually take the file being posted.
Let's asume you already did that, and C# already has an on click event. Then you'll have to write something like

string FileToSave = fileupload1.FileName;
fileupload1.SaveAs(Server.MapPath("~/") + FileToSave);







我建议您为项目创建一个额外的文件夹来存储上传的文件。

此外,如果有人试图上传具有相同名称的文件,请在c#中添加一个if语句,这样就不会出现错误...








I recommend you to create an additional folder to your project to store files uploaded.
Also, include an additional if statement to your c# in case someone tries to upload a file with the same name so you don't get an error as in...


if (File.Exists(Server.MapPath("~/") + FileToSave))
{
      ...save as another name
}





另外需要注意的是确保FileUploader有一份文件。布尔属性fileupload1.HasFile可用于此。



您还可以使用Math.Rand()或其他东西为文件创建新名称。



Additional caution would be to make sure the FileUploader has a file. Boolean property fileupload1.HasFile can be used for that.

You can also create a new name for the file using Math.Rand() or something.


这篇关于C#Sql Excel上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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