2016-09-28 4 views
0

문자열을 통과 한 데이터가 저장된 후 오류가 표시됩니다. 지정된 경로 형식이 지원되지 않습니다. 잘못된 것이거나 url 변환기 코드를 넣었습니다. 잘못된 장소?오류 System.NotSupportedException : 지정된 경로의 형식이 지원되지 않습니다.

try 
{ 
    connect.Open(); 
    OleDbCommand command = new OleDbCommand(); 
    command.Connection = connect; 
    command.CommandText = string.Format("insert into RegisterItem([Name], [Url],[Description], [Price]) values('{0}','{1}','{2}','{3}')", 
             ItemName.Text, 
             ItemUrl.Text, 
             ItemDescription.Text, 
             ItemPrice.Text); 

    command.ExecuteNonQuery(); 
    MessageBox.Show("Data Saved"); 

    txtID1.Text = txtUsername.Text; 
    txtName1.Text = ItemName.Text; 
    txtDescription1.Text = ItemDescription.Text; 
    txtPrice1.Text = ItemPrice.Text; 
    ItemName.Text = ""; 
    ItemDescription.Text = ""; 
    ItemPrice.Text = ""; 
    string str = ItemUrl.Text; 
    pictureBox1.ImageLocation = str; 
    string str1 = textBox1.Text; 
    Image img = Image.FromFile(str); 
    pictureBox1.Image = img; 
} 
catch (Exception ex) 
{ 
    MessageBox.Show("Error " + ex); 
} 
finally 
{ 
    if (Connect != null) { connect.Close(); } 
} 
+1

'ItemUrl'에 무엇이 있습니까? 우리는 당신의 컴퓨터를 볼 수 없습니다 :) – Pikoh

+0

그것은 텍스트 상자입니다, 당신이 그림을 입력 할 것입니다. pictureBox1에 –

+1

하지만 예외를 일으키는 'ItemUrl.Text' 값은 무엇입니까? – slawekwin

답변

1

이 문제를 일으키는

 Image img = Image.FromFile(str); 

입니다. URL에서 이미지를로드 할 수 없지만 파일 경로 여야합니다. URL에서 이미지를로드하기 위해

, 당신은 실제로

 WebRequest wr = WebRequest.Create("https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg"); 
     Image img; 
     using (var rs = wr.GetResponse().GetResponseStream()) 
     { 
      img = Image.FromStream(rs); 
     } 

, 당신은 완전히 코드의이 부분은 정확하게 모든 작업을 수행

Image img = Image.FromFile(str); 
pictureBox1.Image = img; 

를 생략 할 수 있습니다

pictureBox1.ImageLocation = str; 

Image.FromFile은 디스크 파일에서만로드되지만 ImageLocation을 설정하면 url에서로드 할 수 있고 동시에 d 캔버스에 원본과 이미지

+0

정말요? 왜냐하면 내가 다른 코드를 변경하기 전에 이것은 잘 작동한다. 직접 링크 URL을 넣는 동안로드한다. –

+0

어쨌든이 방법이 작동 할까? postimage.org와 같은 웹 사이트에서 변환 한 후 직접 링크로로드 –

+0

C : \ Users \ Teronkee \ Pictures \ 98b288f6-e204-40fe-a4f3-cb83a21f4be3.jpg와 같은 파일 경로 링크를 입력 한 후 이미지를 즉시로드 할 수있는 방법이 있습니까? ? 질수가 그것을 보관하는 것, 내가 사용하는 방법은 찾아보기 기능을 지원합니다 –

관련 문제