<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: code for Retrieve image from a picture library working in visual web part, but in infopath</title><link>https://www.infopathdev.com:443/forums/thread/62701.aspx</link><pubDate>Sat, 01 Jan 2011 16:19:41 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:62701</guid><dc:creator>Potemkine</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/62701.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=62701</wfw:commentRss><description>Hi, if you plan to use infopath filler, you can use directly sharepoint dll because your client doesn&amp;#39;t have this dll on their desktop. You can use web service to &amp;quot;speak&amp;quot; to SHarepoint I already reply on your other post about that.</description></item><item><title>code for Retrieve image from a picture library working in visual web part, but in infopath</title><link>https://www.infopathdev.com:443/forums/thread/62697.aspx</link><pubDate>Sat, 01 Jan 2011 08:59:19 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:62697</guid><dc:creator>venkatzeus</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/62697.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=62697</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Wishing all a very Happy and Prosperous New Year.&lt;/p&gt;
&lt;p&gt;I am new to creating code&amp;nbsp;in Infopath. The requirement is to search for a image in the picture library and show that image. This scenario is needed in online as well as offline. &lt;/p&gt;
&lt;p&gt;So, i chose Infopath filler 2010. I am able to retrieve the image and show in a visual web part created using VS 2010. But I am not sure of doing it in infopath.&lt;/p&gt;
&lt;p&gt;Following are the controls i have in the Infopath filler form. I have a textbox called &amp;quot;field12&amp;quot;, and a button called search. Below that i have added a table. In the first td, I added a rich textbox to show the image. The id of the richtextbox field is &amp;quot;Image1&amp;quot;. The picture library in the sharepoint site is called &amp;quot;MyPictureLibrary&amp;quot;&lt;/p&gt;
&lt;p&gt;This is the code i have used in Visual web part, while creating in VS 2010, which works fine.&lt;/p&gt;
&lt;p&gt;[CODE]&lt;/p&gt;
&lt;p&gt;protected void BtnSearch_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;SPSecurity.RunWithElevatedPrivileges(&lt;br /&gt;&amp;nbsp;delegate()&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;string FileImageNumber = FetchImagefromPiclib();&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;);&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;public string FetchImagefromPiclib()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;string fileImageNumber = string.Empty;&lt;br /&gt;&amp;nbsp;using (SPSite site = new SPSite(SPContext.Current.Site.ID, SPContext.Current.Site.Zone))&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;using (SPWeb currentweb = site.OpenWeb(SPContext.Current.Web.ID))&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;currentweb.AllowUnsafeUpdates = true;&lt;br /&gt;&amp;nbsp;SPList list = currentweb.Lists[&amp;quot;MyPictureLibrary&amp;quot;];&lt;br /&gt;&amp;nbsp;SPQuery oPostQuery = new SPQuery();&lt;br /&gt;&amp;nbsp;oPostQuery.RowLimit = 1;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;StringBuilder query = new StringBuilder();&lt;br /&gt;&amp;nbsp;query.Append(&amp;quot;&amp;lt;View&amp;gt;&amp;quot;)&lt;br /&gt;&amp;nbsp;.Append(&amp;quot;&amp;lt;Query&amp;gt;&amp;quot;)&lt;br /&gt;&amp;nbsp;.Append(&amp;quot;&amp;nbsp; &amp;lt;Where&amp;gt;&amp;quot;)&lt;br /&gt;&amp;nbsp;.Append(&amp;quot;&amp;nbsp; &amp;lt;/Where&amp;gt;&amp;quot;)&lt;br /&gt;&amp;nbsp;.Append(&amp;quot;&amp;lt;/Query&amp;gt;&amp;quot;)&lt;br /&gt;&amp;nbsp;.Append(&amp;quot;&amp;lt;RowLimit&amp;gt;&amp;quot; + 1)&lt;br /&gt;&amp;nbsp;.Append(&amp;quot;&amp;lt;/RowLimit&amp;gt;&amp;quot;)&lt;br /&gt;&amp;nbsp;.Append(&amp;quot;&amp;lt;/View&amp;gt;&amp;quot;);&lt;br /&gt;&amp;nbsp; oPostQuery.Query = query.ToString();&lt;br /&gt;&amp;nbsp;SPListItemCollection collListItems = list.GetItems(oPostQuery);&lt;br /&gt;&amp;nbsp;list.Update();&lt;br /&gt;&amp;nbsp;SPFolder folder = list.RootFolder;&lt;br /&gt;&amp;nbsp;if (collListItems.Count != 0)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;foreach (SPListItem oListItem in collListItems)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;string imageUrl = SPContext.Current.Site.Url + &amp;quot;/&amp;quot; + list + &amp;quot;/&amp;quot; + oListItem.File.Name;&lt;br /&gt;&amp;nbsp;string thumbUrl = imageUrl.Substring(0, imageUrl.LastIndexOf(&amp;#39;/&amp;#39;));&lt;br /&gt;&amp;nbsp;thumbUrl = thumbUrl + &amp;quot;/_t/&amp;quot; + oListItem.File.Name.Replace(&amp;#39;.&amp;#39;, &amp;#39;_&amp;#39;) + &amp;quot;.jpg&amp;quot;;&lt;br /&gt;&amp;nbsp;Image1.ImageUrl = thumbUrl;&lt;br /&gt;&amp;nbsp;Image1.ToolTip = (oListItem[&amp;quot;Title&amp;quot;] != null) ? oListItem[&amp;quot;Title&amp;quot;].ToString() : &amp;quot;No Title&amp;quot;;&lt;/p&gt;
&lt;p&gt;// sanatize data from SharePoint &lt;br /&gt;fileImageNumber = (oListItem[&amp;quot;Title&amp;quot;] != null) ? oListItem[&amp;quot;Title&amp;quot;].ToString() : &amp;quot;No Title&amp;quot;;&lt;br /&gt;int itemId = oListItem.ID;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&amp;nbsp; return fileImageNumber;&lt;br /&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;[/CODE]&lt;/p&gt;
&lt;p&gt;When i try to debug, it breaks at spsecurity, with error as Invalid COM exception. In the central admin as well as in the site, I have set User Profile to true.&lt;/p&gt;
&lt;p&gt;How to use the above code in Infopath?&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;</description></item></channel></rss>