Veritabanında Olan resim Kayıtlarının Klasör İçersindeki Varlığını Kontrol etmek

C# Tarafı metod İle

public void resimKontrol() { SqlConnection baglanti1 = new SqlConnection(cs1); SqlCommand cmd1 = new SqlCommand("TRUNCATE TABLE resim_kontrol", baglanti1); baglanti1.Open(); cmd1.ExecuteNonQuery(); baglanti1.Close(); //System.IO.File.Move(@"C:\Users\Lenovo\Desktop\deneme\" + kod_degiskeni + ".jpg", @"C:\Users\Lenovo\Desktop\deneme\" + kod_degiskeni + "" + -1 + ".jpg"); SqlConnection baglanti = new SqlConnection(cs1); SqlCommand cmdcek = new SqlCommand("SELECT kodref FROM resim", baglanti); baglanti.Open(); SqlDataReader dr = cmdcek.ExecuteReader(); while (dr.Read()) { string kod_degiskeni = dr["kodref"].ToString(); string resimkontrol_degiskeni = @"C:\Users\Lenovo\Documents\Visual Studio 2013\WebSites\CaglayanGrup\images\urunler\" + kod_degiskeni + ".jpg"; if (File.Exists(resimkontrol_degiskeni)) { //ListBox1.Items.Add(kod_degiskeni+" var"); //Label1.Text = ListBox1.Items.Count.ToString(); } else { //ListBox2.Items.Add(kod_degiskeni+" yok"); //Label2.Text = ListBox2.Items.Count.ToString(); SqlConnection baglantiekle = new SqlConnection(cs1); SqlCommand eklecmd = new SqlCommand("insert into resim_kontrol (kodref,kontrol) values('" + kod_degiskeni + "','0')", baglantiekle); baglantiekle.Open(); eklecmd.ExecuteNonQuery(); baglantiekle.Close(); } } dr.Close(); baglanti.Close(); GridView2.AllowPaging = false; lblresimkontrol.Text = GridView2.Rows.Count.ToString()+ " Adet Resim Eksik Durumdadır!"; lblresimkontrol.ForeColor = System.Drawing.Color.Red; lblresimkontrol.Font.Bold = true; GridView2.AllowPaging = true; GridView2.DataBind(); }

Form.cs Tarafı

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="rkSqlDataSource1" ForeColor="#333333" GridLines="Horizontal" DataKeyNames="id"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="id" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="id" > <HeaderStyle CssClass="tacenter" /> <ItemStyle CssClass="tacenter" Width="50px" /> </asp:BoundField> <asp:BoundField DataField="kodref" HeaderText="KOD REFERANS" SortExpression="kodref" > <HeaderStyle CssClass="tacenter" /> <ItemStyle CssClass="tacenter" Width="150px" /> </asp:BoundField> <asp:CheckBoxField DataField="kontrol" HeaderText="KONTROL" SortExpression="kontrol" > <ItemStyle CssClass="tacenter" Width="50px" /> </asp:CheckBoxField> </Columns> <EditRowStyle BackColor="#7C6F57" /> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#E3EAEB" /> <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F8FAFA" /> <SortedAscendingHeaderStyle BackColor="#246B61" /> <SortedDescendingCellStyle BackColor="#D4DFE1" /> <SortedDescendingHeaderStyle BackColor="#15524A" /> </asp:GridView> <asp:Label ID="lblresimkontrol" runat="server" Text="Label"></asp:Label> <asp:SqlDataSource ID="rkSqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:urunCS %>" SelectCommand="SELECT * FROM [resim_kontrol]" ></asp:SqlDataSource> <br />

Hiç yorum yok:

Yorum Gönder