FileStream fs = new (3个参数)我估计是后两个参数的问题
解决方案 »
- WPF程序,运行时偶尔会出现窗体无响应,大家都是怎样排查原因和解决的?
- Datagridview表头获取
- c# 求解决方案任务管理器关闭winform程序 此程序弹出是否关闭选择框
- Winform 如何调整DataGridView数据大小
- CustomForm实现Form半透明的问题
- 麻烦问一下怎么在 TreeView 中添加父节点和子节点??
- C#里面调用vc++里的函数,献分,急!
- 水晶报表的高手朋友来看
- 简单问题,想用年份表示一个字符串怎么做??
- 今天我生日,1700分大放送,为增加节日气氛,出一题C#题目给20分,内容不限先到先得。
- C#编写画图板问题
- 高分求权限管理代码(C#,winform)。。
private void panel1_DragDrop(object sender, DragEventArgs e)
{
try
{
new FileIOPermission(PermissionState.Unrestricted).Assert();
// StringBuilder fileTable = new StringBuilder();
foreach (string fileListItem in (e.Data.GetData(DataFormats.FileDrop) as string[]))
{
Bitmap bm = new Bitmap(fileListItem);
//get image name
int pos = fileListItem.LastIndexOf(@"\") + 1;
string name = fileListItem.Substring(pos); ;
str = str + 1;
Drag darg = new Drag(bm, name, str-2, ds);
darg.Left = x * 175 + 15 * (x + 1) + panel1.AutoScrollPosition.X;
darg.Top = y * 150 + 10 * (y + 1) + panel1.AutoScrollPosition.Y;
darg.Width = 175;
darg.Height = 150;
//imgList[x] = fileListItem;
dr = ds.Tables[0].NewRow();
dr[0] = x;
dr[1] = fileListItem;
ds.Tables[0].Rows.Add(dr);
this.panel1.Controls.Add(darg); x += 1;
if (x % 3 == 0)
{
x = 0;
y += 1; } }
CodeAccessPermission.RevertAssert();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}2。上传图片时
private void CopyWithProgress(string[] filenames)
{
// Display the ProgressBar control.
this.progressBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
progressBar1.Minimum = 1;
// Set Maximum to the total number of files to copy.
progressBar1.Maximum = filenames.Length;
// MessageBox.Show(filenames.Length.ToString());
// Set the initial value of the ProgressBar.
progressBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being copied.
progressBar1.Step = 1;
for (int x = 0; x < filenames.Length; x++)
{
int pos = filenames[x].LastIndexOf(@"\") + 1;
string filename = filenames[x].Substring(pos);
this.labFilename.Text = filenames[x];
//这里出现了问题,
FileStream fs = File.Create(filename[x].ToString());
//这里出现了问题
byte[] info=new byte[fs.Length];
fs.Close();
if (uploadService.UploadFiles(info, @"img\" + filename))
{
// MessageBox.Show("Upload Images");
}
else
{
MessageBox.Show("No Upload Images"); }
progressBar1.PerformStep();
Bitmap bm = new Bitmap(filenames[x]);
this.pictureBox1.Image = bm;
} }
我写了个类,将文件上传到服务器上,在本机上可以正常,但服务器上则不行,提示错误:
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.网上找了关于安全的资料,没找到相关的说法,有没有高手这方面的资料?
这一句从文件创建位图实际已经独占了了文件。
可以改成这样。
using (Bitmap bit = new Bitmap(fileListItem))
{ this.panel1.BackgroundImage = bit.GetThumbnailImage(panel1.Width, panel1.Height, null, IntPtr.Zero);
}
另外你的文件上传代码中
FileStream fs = File.Create(filename[x].ToString());
//这里出现了问题
byte[] info=new byte[fs.Length];
fs.Close();
这几句似乎逻辑就有问题。文件已经存在了,为什么又要新建文件而不是打开读取,那文件长度字节不是成为0了吗?