【C#-保存文件而不使用“保存文件”对话框】教程文章相关的互联网学习教程文章

C#实现上传照片到物理路径,并且将地址保存到数据库的小例子【图】

效果:思路: 首先,获取图片物理地址,然后进行判断将图片保存到文件夹下,再将图片的信息保存到数据库。 数据库: 代码如下:create table image1(ID int identity(1,1) primary key,ImageName varchar(100) ,ImageType varchar(20),ImagePath varchar(200)) 代码: 代码如下:<body> <form id="form1" runat="server"> <div> <table> <tr> <td colspan="2" style="height: 21px"> ...

C#保存上传来的图片示例代码

代码如下:[HttpPost] public string UploadImage() { //string ss = Request.Form["uploadFile"]; //return ss; HttpPostedFileBase uploadFile = Request.Files[0]; string fileName = uploadFile.FileName; int fileSize = uploadFile.ContentLength; string fileExt = Path.GetExtension(fileName).ToLower(); string message = ""; if (!(fileExt == ".png" || fileExt == ".gif" || fileExt == ".jpg" || fileExt == ".jpeg")...

C# 文件保存到数据库中或者从数据库中读取文件

其实,方法非常的简单,只是可能由于这些朋友刚刚开始编程不久,一时没有找到方法而已。下面介绍一下使用C#来完成此项任务。 首先,介绍一下保存文件到数据库中。 将文件保存到数据库中,实际上是将文件转换成二进制流后,将二进制流保存到数据库相应的字段中。在SQL Server中该字段的数据类型是Image,在Access中该字段的数据类型是OLE对象。 代码如下://保存文件到SQL Server数据库中 FileInfo fi=new FileInfo(fileName); File...

C#从数据库读取数据到DataSet并保存到xml文件

System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.IO;public class TestWriteXML {public static void Main(){String strFileName = c:/temp/out.xml;SqlConnection conn = new SqlConnection(server=localhost;uid=sa;pwd=;database=db);String strSql = SELECT name,age FROM people;SqlDataAdapter adapter = new SqlDataAdapter();adapter.SelectCommand = new SqlCommand(strSql, co...

C#(WinForm)上传图片保存到数据库和从数据库读取图片显示到窗体

//浏览图片2 3 private void btnUp_Click(object sender, EventArgs e)4 5 {6 7 OpenFileDialog ofd = new OpenFileDialog();8 9 ofd.Title = "选择要上传的图片";10 11 ofd.Filter = "All Files(*.*)|*.*|位图(*.bmp)|*.bmp|JPEG(*.jpg)|*.jpg";12 13 ofd.ShowDialog();14 15 textBox1.Text = ofd.FileName;16 17 if (!File.Ex...

C# 图片保存到数据库和从数据库读取图片并显示

图片保存到数据库的方法: public void imgToDB(string sql) { //参数sql中要求保存的imge变量名称为@images //调用方法如:imgToDB("update UserPhoto set Photo=@images where UserNo=‘" + temp + "‘"); FileStream fs = File.OpenRead(t_photo.Text); byte[] imageb = new byte[fs.Length]; fs.Read(imageb, 0, imageb.Length); fs.Close(); ...

C#生成唯一的ID保存到数据库

string id = guid.ToString("N");保存到数据库中后,就是一串32位的字符串 C#生成唯一的ID保存到数据库标签:保存 guid 格式 strong blog sys 全球 pre style 本文系统来源:http://www.cnblogs.com/Donnnnnn/p/5996031.html

Linq To Sql进阶系列(六)用object的动态查询与保存log篇【图】

4,测试用例及反思我们用下面的例子来测试下这个函数 Customer c = new Customer(); c.City = "London"; c.Phone = "23236133"; var q = db.Find<Customer>(c).ToList(); 其生成的sql语句为: SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phon...

C#中RichEdit控件,保存文本和图片到mysql数据库

方法1://建立内存流 MemoryStream ms = new MemoryStream(); //ms.Position = 0; //把当前的richtextbox内容包括图片和文本保存到流中 richTextBox1.SaveFile(ms, RichTextBoxStreamType.RichText); byte[] buffer = ms.GetBuffer(); // MySqlConnectString MySqlConnection conn = new MySqlConnection(Properties.Settings.Default.MySqlConne...

C# 用sql语句保存excel

static void SaveExcel(string filePath,DataSet dt){bool hasHeaders = false;string HDR = hasHeaders ? "Yes" : "No";string strConn;if (filePath.Substring(filePath.LastIndexOf(‘.‘)).ToLower() == ".xlsx")strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=" + HDR + ";IMEX=0\"";elsestrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fi...

C# 保存WINFORM窗体截图到本地和FTP【代码】

代码如下:using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace WindowsFormsCaptureTest {class SaveFurnacePic{/// <summary>/// 保存/// </summary>/// <param name="form">窗体</param>/// <param name="furnaceName">将...

 C#保存winform中显示的图片【代码】

C#,保存winform中pictureBox中的图片 SaveFileDialog savedialog = new SaveFileDialog(); savedialog.Title = "附件另存"; savedialog.Filter = "jpg图片|*.JPG|png图片|Bmp 图片|*.bmp|*.PNG|jpeg图片|*.JPEG"; savedialog.FilterIndex = 3;//设置默认文件类型显示顺序 savedialog.RestoreDirectory = true; //点了保存按钮进入 if (pictureBox1.Image != null) {if (savedialog.ShowDialog() == DialogResult.OK){string pictu...

C# 之Richtextbox保存为Byte[] 和读取Byte[]【代码】

将richtextbox内容保存为字节数组Byte[] //使用内存流 using (MemoryStream savefilestream = new MemoryStream()) {richTextBox1.SaveFile(savefilestream, RichTextBoxStreamType.RichText);Byte[] bt = savefilestream.ToArray(); }将richtextbox读取字节数组Byte[] //从数据库中读出Byte[] Byte[] bt = (Byte[])rd[0]; //MessageBox.Show(bt.Length.ToString()); MemoryStream fm = new MemoryStream(bt); richTextBox1.LoadFi...

C#文本转语音并保存wav和MP3文件【图】

回顾上次写博客至今都有4个多月了,最近工作比较的忙没时间写博文。以后会多坚持写博文,与大家分享下最近遇到的问题。最近因为项目需要,研究了下用C#开发TTS。下面把大体的思路给大家说说,希望对大家有所帮助。首先需要了解下MS的SAPI,它是微软的语音API。它包括了语音识别SR引擎和语音合成SS引擎两种语音引擎。等下会给大家看下语音合成SS引擎。它由不同的版本,操作系统的不同使用的版本不同,不过我喜欢使用其他的合成语音包...

C# 将表格数据保存到Excel文件中(

前提应该是:电脑必须有安装Excel 正确代码: string path = System.Environment.CurrentDirectory+"\\"+DateTime.Now.ToString("yyyyMMddHHmmssfff"); Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();? int rowIndex = 1; int colIndex = 0;? excel.Application.Workbooks.Add(true);? foreach (DataColumn col in dt.Columns) { ? ? colIndex++; excel.Cells[1, colInde...