c# 使用文件流上传的问题

橙子_粒子 2014-06-13 03:30:14
在本地写好的程序发布到服务器上在访问时发现,打开的文件路径却是服务器的磁盘路径,请问怎样将其改成点击上传时显示成本地的磁盘的路径
...全文
425 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
获取临时文件目录问题 private void button1_Click(object sender, EventArgs e) { textBox1.Text = Path.GetTempPath();//获取临时文件目录路径 } private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label1.Location = new System.Drawing.Point(9, 9); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(104, 16); this.label1.TabIndex = 0; this.label1.Text = "临时文件目录"; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(12, 28); this.textBox1.Name = "textBox1"; this.textBox1.ReadOnly = true; this.textBox1.Size = new System.Drawing.Size(264, 21); this.textBox1.TabIndex = 1; // // button1 // this.button1.Location = new System.Drawing.Point(201, 55); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 2; this.button1.Text = "获取"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Frm_Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(279, 82); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Controls.Add(this.label1); this.Name = "Frm_Main"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "获取临时文件目录"; this.ResumeLayout(false); this.PerformLayout(); }
  • 打赏
  • 举报
回复
设计一个程序,一定要从前端操作入手进行分析设计。 那种满脑子只有一些编程语句、满脑子就是“增删改查”的想法,根本不能设计出好的程序。如果一个人用6、7年时间死记硬背这些东西,或许会“熟练地”做出一些千篇一律的便宜货。但是只有从前端出发的人,才能掌握程序设计要领。
  • 打赏
  • 举报
回复
一个页面,对于可下载的资源文件要如何显示它的名称和路径,这是在网页美工设计之时就进行UI设计的。然后才考虑如何设计通讯数据结构、前端如何采集数据、后台如何保存数据等等问题。 我遇到一些人,他们自己不从事这个设计工作,一拖再拖之后公司只能把稍微需要一点动脑筋思考的页面都推给同事中某一个人去做,这样的公司不倒闭才怪。
tcmakebest 2014-06-15
  • 打赏
  • 举报
回复
这种问题根本与技术无关,应该自己最清楚啊
  • 打赏
  • 举报
回复
引用 楼主 u011822950 的回复:
在本地写好的程序发布到服务器上在访问时发现,打开的文件路径却是服务器的磁盘路径,
既然已经设计了一个文件显示机制,那么谁让你显示服务器的磁盘路径呢? 如果根本就是你的老师给你抄的程序,那么你去问你的老师吧。如果是从网上随便抄来的,那么你要动点脑子,自己来设计这个程序,才可能有点能耐改变它。遇到问题了你就扔掉刚刚抄来的程序,然后靠别人另外给一个程序抄,这不现实。
ffg_2460057139 2014-06-15
  • 打赏
  • 举报
回复
以流的形式存储图片到数据库中 protected void imgbtnCreate_Click(object sender, ImageClickEventArgs e) { string PerHomeName=tbPerHomeName.Text;//获取空间名 string PerHomeSign=txtPerSign.Text; //获取个性签名 string imgPath = uploadFile.PostedFile.FileName;//获取文件件名 string lastName = imgPath.Substring(imgPath.LastIndexOf(".") + 1);//获取文件上传后缀名CodeGo.net SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conStr"]); conn.Open(); if (uploadFile.PostedFile.FileName != "" && lastName.ToLower() == "jpg" || lastName.ToLower() == "gif") { if (uploadFile.PostedFile.ContentLength > 40960) { Response.Write("<script language='javaScript'>alert('你上传的图片超过了40KB!')</script>"); return; } int imgLength = uploadFile.PostedFile.ContentLength;//获取上传文件大小 Byte[] imageData = new Byte[imgLength]; //定义Byte数组 HttpPostedFile hp = uploadFile.PostedFile;//创建访问客户端上传文件的对象 Stream imagestream = hp.InputStream;//创建数据流对象 //将图片数据放到image数据对象实例中,其中0代表数组指针的起始位置,imagelength表示要读取流的长度 imagestream.Read(imageData, 0, imgLength); string sqlstr = "insert into PerHomeDetail(PerHomeName,PerHomeSign,PerHomeLogo)values('" + PerHomeName + "','" + PerHomeSign + "',@ImageData)"; SqlCommand comm = new SqlCommand(sqlstr, conn); comm.Parameters.Add("@ImageData", SqlDbType.Image); comm.Parameters["@ImageData"].Value = imageData; comm.ExecuteNonQuery(); conn.Close(); Response.Write("<Script>alert('个人空间创建成功!')</Script>"); } else { Response.Write("<script>alert('上传头像不能为空,且格式必须为gif或jpg!');location='javascript:history.go(-1)'</script>"); } }
破碎的脸 2014-06-13
  • 打赏
  • 举报
回复
Web还是Winform???本地路径是要传参的。。。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧