bin/debug 폴더에 파일을 복사하는 대신 원본 위치에서 데이터를 가져올 수있는 방법이 있습니까? 로컬 프린터로 파일을 보내려합니다. 하지만 내 C# 응용 프로그램은 파일을 bin/debug 폴더로 복사 할 때만 파일을 보낼 수 있습니다. 내가 끝날 수있는 방법이 있니?항상 bin/debug 폴더에 파일이 없다는 것을 묻습니다.
코드 :
private string image_print()
{
OpenFileDialog ofd = new OpenFileDialog();
{
InitialDirectory = @"C:\ZTOOLS\FONTS",
Filter = "GRF files (*.grf)|*.grf",
FilterIndex = 2,
RestoreDirectory = true
};
if (ofd.ShowDialog() == DialogResult.OK)
{
string filename_noext = Path.GetFileName(ofd.FileName);
string path = Path.GetFullPath(ofd.FileName);
img_path.Text = filename_noext;
string replacepath = @"bin\\Debug";
string fileName = Path.GetFileName(path);
string newpath = Path.Combine(replacepath, fileName);
if (!File.Exists(filename_noext))
{
// I don't like to copy the file to the debug folder
// is there an alternative solution?
File.Copy(path, newpath);
if (string.IsNullOrEmpty(img_path.Text))
{
return "";
}
StreamReader test2 = new StreamReader(img_path.Text);
string s = test2.ReadToEnd();
return s;
}
}
}
private void button4_Click(object sender, EventArgs e)
{
string s = image_print() + Print_image();
if (!String.IsNullOrEmpty(s) &&
!String.IsNullOrEmpty(img_path.Text))
{
PrintFactory.sendTextToLPT1(s);
}
}
이 무슨 뜻 이죠, 당신을하지 않습니다
당신은 선택된 파일의 전체 경로를 사용해야합니까? 런타임 예외가 발생합니까? –
@GrantWinney 내 말은 .. 위의 코드는 내가 일을 할 수있게 해준다.하지만 System.IO.File.Copy (path, newpath);'파일을 디버그 폴더에 복사하고 싶지 않다. .. 파일을 선택하고 직접 디버그 폴더로 복사하는 대신 컴퓨터로 보내려고합니다. –
img_path 및 path의 값은 무엇입니까? – Adam47