| |

VerySource

 Forgot password?
 Register
Search
Author: qwerqwer1

How does uploading and downloading files in ASP.NET work?

[Copy link]

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-31 15:00:01
| Show all posts
You first create a default Ftp website in Internet Information Services.

OleDbParameter ContentsParas = new OleDbParameter("@FileBody",OleDbType.Binary);
ContentsParas.Value = FileBody;
OleDbParameter[] Paras = {ContentsParas};
this.SqlExecuteNonQuery(strSql,Paras);
private void SqlExecuteNonQuery(string strSqltext,OleDbParameter[] parameters)
{
string connectionstring = System.Configuration.ConfigurationSettings.AppSettings["FileSQL"].ToString();// "Provider=SQLOLEDB;data source=DDZ/DDZ;initial catalog=Exam;persist security info=False;user id=sa; password=";//System.Configuration.ConfigurationSettings.AppSettings["strSqlServerConnection"];
OleDbConnection cnn = new OleDbConnection(connectionstring);
OleDbCommand cmm = new OleDbCommand(strSqltext,cnn);
cmm.CommandText = strSqltext;
foreach(OleDbParameter param in parameters)
{
cmm.Parameters.Add(param);
}

cnn.Open();
cmm.ExecuteNonQuery();
cnn.Close();
}
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-31 17:15:02
| Show all posts
download:
DataBaseType = System.Configuration.ConfigurationSettings.AppSettings["DataBaseType"].ToString();
string FileType;
string strSql = "SELECT * FROM JXNF_FILE WHERE FILEID="+RecordId;
DataTable dt = Util.DBFactory.NonTransactionPowerPlant.ExecuteDataTable(strSql);
//System.Collections.Specialized.NameValueCollection myCollection = Util.DBFactory.NonTransactionPowerPlant.ExecuteNameValueCollection(strSql);
byte[] FileByte;
int len;
MemoryStream myStream; //Create a stream whose support storage area is memory
if (!Object.Equals(dt.Rows,null))
{
myStream = new MemoryStream();
FileType = dt.Rows[0]["FileType"].ToString();
FileByte = (byte[])dt.Rows[0]["FileContent"];
To
myStream.Write (FileByte, 0, FileByte.Length);
len = FileByte.Length;

Response.ClearHeaders();
Response.ContentType = FileType;
Response.OutputStream.Write(FileByte, 0, len);
Response.Flush();
myStream.Close ();
}
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-8-6 13:00:02
| Show all posts
Thank you guys
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-6 16:00:01
| Show all posts
These codes do not consider whether they are downloaded by legitimate users!
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-6 16:15:01
| Show all posts
private void btnup_Click(object sender, System.EventArgs e)
{
string MyUploadDir;
int i;
string Title=TxtTitle.Text;
//Response.Write (Title);
//Response.End();
if(Title.Length==0)
{
Response.Write("<script>alert('Please fill in the title of the file!');history.back();</script>");
Response.End();}

MyUploadDir=Server.MapPath("") + "\\System";
DirectoryInfo Target=new DirectoryInfo(MyUploadDir);
if(!Target.Exists)
{Directory.CreateDirectory(MyUploadDir);}
System.Web.HttpFileCollection MyFileColl = Request.Files;
//Response.Write (MyFileColl.Count);
//Response.End();
for(i=0;i<MyFileColl.Count;i++)
{
int j = MyFileColl[i].FileName.LastIndexOf('\\');
string File_Name_NoPath=MyFileColl[i].FileName.Substring(j);
string LocalFile = MyUploadDir + File_Name_NoPath;
System.IO.FileInfo fi = new System.IO.FileInfo(LocalFile);
if(fi.Exists)
{
Response.Write("<script>alert('The file you uploaded already exists! Please change the file name!');history.back();</script>");
Response.End();}
else
{
char[] MyChar = {'\\'};
File_Name_NoPath=File_Name_NoPath.TrimStart(MyChar);
File_Name_NoPath="/jpgl/System/"+File_Name_NoPath;
//Response.Write(strInsert);
//Response.End();
MyFileColl[i].SaveAs(LocalFile);
string strInsert="insert into jp_system(jp_systitle,jp_sysaddress) values ​​('"+Title+"','"+File_Name_NoPath+"') ";
//Response.Write(strInsert);
//Response.End();
SqlConnection MyConnection = new SqlConnection(strConnection);
MyConnection.Open ();
SqlCommand MyCommand=new SqlCommand(strInsert,MyConnection);
MyCommand.ExecuteNonQuery();
//MyConnection.Close();
}
}
Reply

Use magic Report

1

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 Invalid IP Address

Post time: 2020-8-6 16:45:01
| Show all posts
Put the downloaded link in the panel, right? This is displayed if it is legal, and it is not displayed if it is illegal. . . . . . . .
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list