<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: In line code to upload (supportive) documents</title>
	<atom:link href="http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/feed/" rel="self" type="application/rss+xml" />
	<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/</link>
	<description>Bits and Bytes of SharePoint / MOSS</description>
	<lastBuildDate>Fri, 23 Oct 2009 21:28:43 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Farhan Faiz</title>
		<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-568</link>
		<dc:creator>Farhan Faiz</dc:creator>
		<pubDate>Fri, 17 Jul 2009 20:42:32 +0000</pubDate>
		<guid isPermaLink="false">http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-568</guid>
		<description>I don’t think this is much different on sharepoint object model level. Let me know if you have any issues.</description>
		<content:encoded><![CDATA[<p>I don’t think this is much different on sharepoint object model level. Let me know if you have any issues.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nixBS</title>
		<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-563</link>
		<dc:creator>nixBS</dc:creator>
		<pubDate>Thu, 16 Jul 2009 05:45:05 +0000</pubDate>
		<guid isPermaLink="false">http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-563</guid>
		<description>hi Farhan
my question is:how to upload an attachment in a list (not in document library) corresponding to a data record..

I need to use some SPQuesry for getting a particular record???
Can u help in this case..

Thnx in advance..</description>
		<content:encoded><![CDATA[<p>hi Farhan<br />
my question is:how to upload an attachment in a list (not in document library) corresponding to a data record..</p>
<p>I need to use some SPQuesry for getting a particular record???<br />
Can u help in this case..</p>
<p>Thnx in advance..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Farhan Faiz</title>
		<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-549</link>
		<dc:creator>Farhan Faiz</dc:creator>
		<pubDate>Mon, 06 Jul 2009 17:38:20 +0000</pubDate>
		<guid isPermaLink="false">http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-549</guid>
		<description>opo,

I don’t think this is much different on sharepoint object model. Let me know if you have any issues.

Regards,</description>
		<content:encoded><![CDATA[<p>opo,</p>
<p>I don’t think this is much different on sharepoint object model. Let me know if you have any issues.</p>
<p>Regards,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: opo Herrera</title>
		<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-544</link>
		<dc:creator>opo Herrera</dc:creator>
		<pubDate>Fri, 03 Jul 2009 17:47:57 +0000</pubDate>
		<guid isPermaLink="false">http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-544</guid>
		<description>hi guys!! how can i add the same feature on any of my lists. What i want is to see the name of the attachments (multiple of them) and have the opportunity to upload up to to 10.

please help me..

Opo</description>
		<content:encoded><![CDATA[<p>hi guys!! how can i add the same feature on any of my lists. What i want is to see the name of the attachments (multiple of them) and have the opportunity to upload up to to 10.</p>
<p>please help me..</p>
<p>Opo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ali</title>
		<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-340</link>
		<dc:creator>Ali</dc:creator>
		<pubDate>Tue, 26 Aug 2008 15:15:03 +0000</pubDate>
		<guid isPermaLink="false">http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-340</guid>
		<description>I tried that but that is not what we are looking for. Anyways, i guess folks at my place have figured out another way to handle it. Thanks anyways.</description>
		<content:encoded><![CDATA[<p>I tried that but that is not what we are looking for. Anyways, i guess folks at my place have figured out another way to handle it. Thanks anyways.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Farhan Faiz</title>
		<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-339</link>
		<dc:creator>Farhan Faiz</dc:creator>
		<pubDate>Mon, 25 Aug 2008 20:22:31 +0000</pubDate>
		<guid isPermaLink="false">http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-339</guid>
		<description>Ali, 

If you are using MOSS 2007, then, enabling document as web page might solve this problem. If yes, then, its great. If no, then we have to find some other way.

Do let me now in case you require further assistance in this regard.</description>
		<content:encoded><![CDATA[<p>Ali, </p>
<p>If you are using MOSS 2007, then, enabling document as web page might solve this problem. If yes, then, its great. If no, then we have to find some other way.</p>
<p>Do let me now in case you require further assistance in this regard.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ali</title>
		<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-337</link>
		<dc:creator>Ali</dc:creator>
		<pubDate>Mon, 25 Aug 2008 17:21:35 +0000</pubDate>
		<guid isPermaLink="false">http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-337</guid>
		<description>Farhan,

I was wondering if you had the same issue while you were doing the same thing with your client. My client needs a document to be posted as word document and should also have the flexibility to view the content as a web page.

My team is asking me to save the document as an MHTML document. One major problem i run into is that the size of the word documents is over 60, if i do the conversion from word to mht file, it would be very cumbersome. I was looking for an automated solution to it.

The other problem that we run in is once the document is converted into mht file, the way mht file looks is a lot different from the original word document. Is there any code/script i could run to align the MHTML text by any chance to your knowledge that it could render it exactly as a .doc file?

Regards,

Ali.</description>
		<content:encoded><![CDATA[<p>Farhan,</p>
<p>I was wondering if you had the same issue while you were doing the same thing with your client. My client needs a document to be posted as word document and should also have the flexibility to view the content as a web page.</p>
<p>My team is asking me to save the document as an MHTML document. One major problem i run into is that the size of the word documents is over 60, if i do the conversion from word to mht file, it would be very cumbersome. I was looking for an automated solution to it.</p>
<p>The other problem that we run in is once the document is converted into mht file, the way mht file looks is a lot different from the original word document. Is there any code/script i could run to align the MHTML text by any chance to your knowledge that it could render it exactly as a .doc file?</p>
<p>Regards,</p>
<p>Ali.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ali</title>
		<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-336</link>
		<dc:creator>Ali</dc:creator>
		<pubDate>Mon, 25 Aug 2008 17:12:29 +0000</pubDate>
		<guid isPermaLink="false">http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-336</guid>
		<description>Hi Farhan,

Sorry for the late reply. I thought if you would message me it would alert me. Anyways, was just looking at your requirements to see if i had the same requirements and saw your comment. 

The solution to the problem was the user who was trying to add the document to the document library, did not had the permissions to do so. I had to do impersonate the user and elevate the previlages.

I was facing one more problem after impersonation. Once the file was added to the doc library, the Title was not getting updated. The Doc.Updated() thing was not working under the ElevatedPrevilages block and was giving an exception. Just have a look at my code and see if that makes sense to you, I also pasted the link while i was write the code as a comment to the site that helped me solve my problem. 

public void AttachDocument(FileUpload file, string URL, string DocumnetTitle)
     {
        SPWeb elevatedRootWeb = null;
         //Without Impersonation, the items of a list could not have been updated
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite elevatedSite = new SPSite(sp.ID))
            {
                elevatedRootWeb = elevatedSite.RootWeb;
            }
        });
            //DocAdded.Update somehow doesn&#039;t inside the RunWithElevatedPrivileges block
            //I instantiated the SPWeb or SPSite and call
            //updates outside the RunWithElevatedPrivileges block
            //Refer to the following code http://howtocode.blogspot.com/2007/06/moss-splistitemupdate-throws-error.html
            elevatedRootWeb.AllowUnsafeUpdates = true;
            SPUser user = elevatedRootWeb.CurrentUser;
            byte[] content = new byte[file.PostedFile.ContentLength];
            URL = URL + file.FileName;
            content = file.FileBytes;
            SPFolder DocLibFolder = elevatedRootWeb.GetFolder(&quot;DLOne&quot;);
            SPFileCollection DocLists = DocLibFolder.Files;
            SPFile FileAdded = DocLists.Add(URL, content, user, user, DateTime.Now.ToUniversalTime(), DateTime.Now.ToUniversalTime());
            SPListItem DocAdded = FileAdded.Item;
            DocName = DocAdded.Name;
            //DocTitle = DocName.Substring(0, DocName.IndexOf(&#039;.&#039;));
            if (DocumnetTitle == &quot;&quot;)
            {
                DocumnetTitle = DocName.Substring(0, DocName.IndexOf(&#039;.&#039;));
            }
            DocAdded[&quot;Title&quot;] = DocumnetTitle;
            DocAdded.Update();
            elevatedRootWeb.AllowUnsafeUpdates = false;
        }

        finally
        {
            elevatedRootWeb.Dispose();
        }
    }
        });
        return stFilename;
    }</description>
		<content:encoded><![CDATA[<p>Hi Farhan,</p>
<p>Sorry for the late reply. I thought if you would message me it would alert me. Anyways, was just looking at your requirements to see if i had the same requirements and saw your comment. </p>
<p>The solution to the problem was the user who was trying to add the document to the document library, did not had the permissions to do so. I had to do impersonate the user and elevate the previlages.</p>
<p>I was facing one more problem after impersonation. Once the file was added to the doc library, the Title was not getting updated. The Doc.Updated() thing was not working under the ElevatedPrevilages block and was giving an exception. Just have a look at my code and see if that makes sense to you, I also pasted the link while i was write the code as a comment to the site that helped me solve my problem. </p>
<p>public void AttachDocument(FileUpload file, string URL, string DocumnetTitle)<br />
     {<br />
        SPWeb elevatedRootWeb = null;<br />
         //Without Impersonation, the items of a list could not have been updated<br />
        try<br />
        {<br />
            SPSecurity.RunWithElevatedPrivileges(delegate()<br />
        {<br />
            using (SPSite elevatedSite = new SPSite(sp.ID))<br />
            {<br />
                elevatedRootWeb = elevatedSite.RootWeb;<br />
            }<br />
        });<br />
            //DocAdded.Update somehow doesn&#8217;t inside the RunWithElevatedPrivileges block<br />
            //I instantiated the SPWeb or SPSite and call<br />
            //updates outside the RunWithElevatedPrivileges block<br />
            //Refer to the following code <a href="http://howtocode.blogspot.com/2007/06/moss-splistitemupdate-throws-error.html" rel="nofollow">http://howtocode.blogspot.com/2007/06/moss-splistitemupdate-throws-error.html</a><br />
            elevatedRootWeb.AllowUnsafeUpdates = true;<br />
            SPUser user = elevatedRootWeb.CurrentUser;<br />
            byte[] content = new byte[file.PostedFile.ContentLength];<br />
            URL = URL + file.FileName;<br />
            content = file.FileBytes;<br />
            SPFolder DocLibFolder = elevatedRootWeb.GetFolder(&#8220;DLOne&#8221;);<br />
            SPFileCollection DocLists = DocLibFolder.Files;<br />
            SPFile FileAdded = DocLists.Add(URL, content, user, user, DateTime.Now.ToUniversalTime(), DateTime.Now.ToUniversalTime());<br />
            SPListItem DocAdded = FileAdded.Item;<br />
            DocName = DocAdded.Name;<br />
            //DocTitle = DocName.Substring(0, DocName.IndexOf(&#8216;.&#8217;));<br />
            if (DocumnetTitle == &#8220;&#8221;)<br />
            {<br />
                DocumnetTitle = DocName.Substring(0, DocName.IndexOf(&#8216;.&#8217;));<br />
            }<br />
            DocAdded["Title"] = DocumnetTitle;<br />
            DocAdded.Update();<br />
            elevatedRootWeb.AllowUnsafeUpdates = false;<br />
        }</p>
<p>        finally<br />
        {<br />
            elevatedRootWeb.Dispose();<br />
        }<br />
    }<br />
        });<br />
        return stFilename;<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Farhan Faiz</title>
		<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-334</link>
		<dc:creator>Farhan Faiz</dc:creator>
		<pubDate>Tue, 19 Aug 2008 20:05:59 +0000</pubDate>
		<guid isPermaLink="false">http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-334</guid>
		<description>Lets try to debug the code. Kindly do the following steps and kindly share the results:

1 - replcae URL in DocLists.Add(URL,content) with a hard coded URL of the file.
2  - Check the size of &quot;content&quot;.

3 - Check the values of DocLibFolder and DocLists using debug.

waiting for your reply.</description>
		<content:encoded><![CDATA[<p>Lets try to debug the code. Kindly do the following steps and kindly share the results:</p>
<p>1 &#8211; replcae URL in DocLists.Add(URL,content) with a hard coded URL of the file.<br />
2  &#8211; Check the size of &#8220;content&#8221;.</p>
<p>3 &#8211; Check the values of DocLibFolder and DocLists using debug.</p>
<p>waiting for your reply.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ali</title>
		<link>http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-333</link>
		<dc:creator>Ali</dc:creator>
		<pubDate>Tue, 19 Aug 2008 19:27:30 +0000</pubDate>
		<guid isPermaLink="false">http://farhanfaiz.wordpress.com/2008/01/21/in-line-code-to-upload-supportive-documents/#comment-333</guid>
		<description>Hi Farhan,

i have been trying your code for 2 days. It some how is not working. I get the error of 
&quot;NullReferenceException was handled by user code &quot;
Troulbe shooting Tips:
Use new keyword to create an object instance.
Check to determine if the object is null before the calling method.
Get general help for this exception.

Attach is an excerpt of my code that was inspired from your style of code.

  public void AttachDocument(FileUpload file)
    {

             byte[] content = new byte[file.PostedFile.ContentLength];
             string URL = &quot;http://oss1:22222/test/&quot; + file.FileName;
             
            content = file.FileBytes;
            SPFolder DocLibFolder = WebSite.GetFolder(&quot;DLOne&quot;);  
            SPFileCollection DocLists = DocLibFolder.Files;
            sp.AllowUnsafeUpdates = true;
            WebSite.AllowUnsafeUpdates = true; 
            SPFile FileAdded = DocLists.Add(URL, content); -&gt; Get an exception at this line
            SPListItem DocAdded = FileAdded.Item;
            DocName = DocAdded.Name;
            DocTitle = DocName.Substring(0, DocName.IndexOf(&#039;.&#039;));
            DocAdded[&quot;Title&quot;] = DocTitle;
            DocAdded.Update();        
    }</description>
		<content:encoded><![CDATA[<p>Hi Farhan,</p>
<p>i have been trying your code for 2 days. It some how is not working. I get the error of<br />
&#8220;NullReferenceException was handled by user code &#8221;<br />
Troulbe shooting Tips:<br />
Use new keyword to create an object instance.<br />
Check to determine if the object is null before the calling method.<br />
Get general help for this exception.</p>
<p>Attach is an excerpt of my code that was inspired from your style of code.</p>
<p>  public void AttachDocument(FileUpload file)<br />
    {</p>
<p>             byte[] content = new byte[file.PostedFile.ContentLength];<br />
             string URL = &#8220;http://oss1:22222/test/&#8221; + file.FileName;</p>
<p>            content = file.FileBytes;<br />
            SPFolder DocLibFolder = WebSite.GetFolder(&#8220;DLOne&#8221;);<br />
            SPFileCollection DocLists = DocLibFolder.Files;<br />
            sp.AllowUnsafeUpdates = true;<br />
            WebSite.AllowUnsafeUpdates = true;<br />
            SPFile FileAdded = DocLists.Add(URL, content); -&gt; Get an exception at this line<br />
            SPListItem DocAdded = FileAdded.Item;<br />
            DocName = DocAdded.Name;<br />
            DocTitle = DocName.Substring(0, DocName.IndexOf(&#8216;.&#8217;));<br />
            DocAdded["Title"] = DocTitle;<br />
            DocAdded.Update();<br />
    }</p>
]]></content:encoded>
	</item>
</channel>
</rss>
