C#中的OpenFileDialog怎么样获取快捷方式的路径?
比如在打开的对话框中我们选择的是文件的快捷方式,但是以下的代码只能获取快捷方式的指向的具体文件的位置.怎么样获取快捷方式的路径,而不是具体文件的路径呢?OpenFileD...
比如在打开的对话框中我们选择的是文件的快捷方式,但是以下的代码只能获取快捷方式的指向的具体文件的位置.怎么样获取快捷方式的路径,而不是具体文件的路径呢?
OpenFileDialog file = new OpenFileDialog();
file.ShowDialog();
if (file.FileName == "")
return;
txtFilePath.Text = file.FileName; 展开
OpenFileDialog file = new OpenFileDialog();
file.ShowDialog();
if (file.FileName == "")
return;
txtFilePath.Text = file.FileName; 展开
2个回答
2013-11-14
展开全部
//FileDialog obj = new OpenFileDialog();
//if (obj.ShowDialog() == DialogResult.OK)
//{
// textBox1.Text = obj.FileName;
//}
开始我是这样写的也可以获取桌面上的迅雷快捷方式啊,文本框中输出的是:C:\Documents and Settings\All Users\桌面\迅雷5.lnk
然后我把你的代码考过去:
OpenFileDialog file = new OpenFileDialog();
file.ShowDialog();
if (file.FileName == "")
return;
textBox1.Text = file.FileName;
也可以做到取出快捷方式啊;
//if (obj.ShowDialog() == DialogResult.OK)
//{
// textBox1.Text = obj.FileName;
//}
开始我是这样写的也可以获取桌面上的迅雷快捷方式啊,文本框中输出的是:C:\Documents and Settings\All Users\桌面\迅雷5.lnk
然后我把你的代码考过去:
OpenFileDialog file = new OpenFileDialog();
file.ShowDialog();
if (file.FileName == "")
return;
textBox1.Text = file.FileName;
也可以做到取出快捷方式啊;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-14
展开全部
string path = "";
private void button5_Click(object sender, EventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
this.txturl.Text = op.FileName;
path = op.FileName;
string filename = path.Substring(path.LastIndexOf("\\") + 1);
string alias = filename.Substring(filename.LastIndexOf(".") + 1);
if (alias == "jpg" || alias == "bmp" || alias == "gif" || alias == "JPG" || alias == "BMP" || alias == "GIF")
{
GetInfo(path);
MemoryStream ms = new MemoryStream(bt);
try
{
this.picpro.Image = Image.FromStream(ms);
this.picpro.SizeMode = PictureBoxSizeMode.StretchImage;
}
catch (Exception ex)
{
MessageBox.Show("上传图片为非法格式!" + ex.Message);
this.txturl.Text = "";
}
}
else
{
MessageBox.Show("上传图片为非法格式!");
this.txturl.Text = "";
}
}
}
private void GetInfo(string path)
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
bt = new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
br.Read(bt, 0, bt.Length);
br.Close();
fs.Close();
}
private void button5_Click(object sender, EventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
this.txturl.Text = op.FileName;
path = op.FileName;
string filename = path.Substring(path.LastIndexOf("\\") + 1);
string alias = filename.Substring(filename.LastIndexOf(".") + 1);
if (alias == "jpg" || alias == "bmp" || alias == "gif" || alias == "JPG" || alias == "BMP" || alias == "GIF")
{
GetInfo(path);
MemoryStream ms = new MemoryStream(bt);
try
{
this.picpro.Image = Image.FromStream(ms);
this.picpro.SizeMode = PictureBoxSizeMode.StretchImage;
}
catch (Exception ex)
{
MessageBox.Show("上传图片为非法格式!" + ex.Message);
this.txturl.Text = "";
}
}
else
{
MessageBox.Show("上传图片为非法格式!");
this.txturl.Text = "";
}
}
}
private void GetInfo(string path)
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
bt = new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
br.Read(bt, 0, bt.Length);
br.Close();
fs.Close();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询