Comments on: SharePoint List Attachment Technical Brief http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/ No GeekSpeak on SharePoint 2007 WSS and MOSS Thu, 17 Jun 2010 02:11:11 -0400 http://wordpress.org/?v=2.8.6 hourly 1 By: Mark Wheeler http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/comment-page-1/#comment-70419 Mark Wheeler Wed, 26 May 2010 17:50:51 +0000 http://www.endusersharepoint.com/?p=5272#comment-70419 I just can't seem to get this to work... 1. Find filename of attachment. 2. Save filename to second list. [sourcecode lang="javascript"] function PreSaveAction() { // alert("PreSave"); $("input[name^='fileupload']").each(function() { if ($(this).val() != "") { alert($(this).val()); var fpath = $(this).val(); var m = fpath.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/); alert(m[2]); } }); $().SPServices({ operation: "UpdateListItems", async: false, listName: "WorkInfo", updates: "" + "" + "" + m[2] + "" + "" + "", completefunc: function(xData, Status) { alert("Status=" + Status + " XML=" + xData.responseXML.xml); } }); return true; } [/sourcecode] I just can’t seem to get this to work…

1. Find filename of attachment.
2. Save filename to second list.

function PreSaveAction() {
	 // alert("PreSave");

$("input[name^='fileupload']").each(function() {
		if ($(this).val() != "") {
			alert($(this).val());
			var fpath = $(this).val();
			var m = fpath.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);

			alert(m[2]); 

	}
	});  

$().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "WorkInfo",
        updates: "" +
                "" +
                "" + m[2] + "" +
                "" +
            "",
        completefunc: function(xData, Status) {
         alert("Status=" + Status + " XML=" + xData.responseXML.xml);
        }
    });
    return true;
}
]]>
By: Shankar Raman http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/comment-page-1/#comment-50547 Shankar Raman Tue, 30 Mar 2010 12:40:24 +0000 http://www.endusersharepoint.com/?p=5272#comment-50547 Hi MG, No need to apologize. I did manage to get this working thanks to Brian's advice. I appreciate your post and getting back to me. Thanks, Shankar. Hi MG,
No need to apologize. I did manage to get this working thanks to Brian’s advice. I appreciate your post and getting back to me.
Thanks,
Shankar.

]]>
By: Michael Greene http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/comment-page-1/#comment-50441 Michael Greene Mon, 29 Mar 2010 18:21:50 +0000 http://www.endusersharepoint.com/?p=5272#comment-50441 Dan, I have run into this need a couple times and haven't found a good solution to be honest. The best way I could solution this was to create a log list, and write my own function to hijack the hyperlink you click when you open the attachment. That function then makes a web service call to write the document name and username into the log list. It's a clunky solution, but I have yet to come up with a better one--if you do, please share! Mike Dan,

I have run into this need a couple times and haven’t found a good solution to be honest. The best way I could solution this was to create a log list, and write my own function to hijack the hyperlink you click when you open the attachment. That function then makes a web service call to write the document name and username into the log list.

It’s a clunky solution, but I have yet to come up with a better one–if you do, please share!

Mike

]]>
By: Michael Greene http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/comment-page-1/#comment-50440 Michael Greene Mon, 29 Mar 2010 18:17:44 +0000 http://www.endusersharepoint.com/?p=5272#comment-50440 Shankar, My apologies, it seems my notification was turned off and I didn't realize you'd posted. Brian's approach will work for attaching documents behind the scenes. Your other option is to use the web services to push a new attachment into a collection; although I've run into some memory issues with that when encoding large files client-side with Javascript. Hope you got everything sorted out, again sorry for the lack of response. Shankar,

My apologies, it seems my notification was turned off and I didn’t realize you’d posted.

Brian’s approach will work for attaching documents behind the scenes. Your other option is to use the web services to push a new attachment into a collection; although I’ve run into some memory issues with that when encoding large files client-side with Javascript.

Hope you got everything sorted out, again sorry for the lack of response.

]]>
By: Brian Bedard http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/comment-page-1/#comment-49198 Brian Bedard Thu, 25 Mar 2010 20:05:17 +0000 http://www.endusersharepoint.com/?p=5272#comment-49198 Yes in a way. I didn't use an application page, I used the out of the box EditForm.aspx list form web part page. When using Rendering Templates, every control can be overriden and you can create a supporting class for it. When you do that, you just subclass SaveButton and override the methods like SaveItem. I used my "new" SaveButton to control field level write access to my list item. Yes in a way. I didn’t use an application page, I used the out of the box EditForm.aspx list form web part page.

When using Rendering Templates, every control can be overriden and you can create a supporting class for it. When you do that, you just subclass SaveButton and override the methods like SaveItem. I used my “new” SaveButton to control field level write access to my list item.

]]>
By: Shankar Raman http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/comment-page-1/#comment-49179 Shankar Raman Thu, 25 Mar 2010 16:13:49 +0000 http://www.endusersharepoint.com/?p=5272#comment-49179 Hi Brian, Thanks for your response. So did you create a custom "SaveButton" control and added it to your application page? Hi Brian,
Thanks for your response. So did you create a custom “SaveButton” control and added it to your application page?

]]>
By: Brian Bedard http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/comment-page-1/#comment-47872 Brian Bedard Sat, 20 Mar 2010 15:08:59 +0000 http://www.endusersharepoint.com/?p=5272#comment-47872 Once the PreSaveAction runs and attachments are submitted, they live in memory in the Request.PostedFiles collection. And the item has an Attachments collection. If you want to manually save attachments in the item, you have to transfer them from the PostedFiles to the Attachments. There is an Add method that takes a filename and a byte array. The PostedFiles collection has HttpPostedFile objects with a Stream property to retrieve the byte array. If you do nothing they will just save into the item for you probably through the same process. When I did this I was overriding SaveItem in the SaveButton control using RenderingTemplates. Once the PreSaveAction runs and attachments are submitted, they live in memory in the Request.PostedFiles collection. And the item has an Attachments collection. If you want to manually save attachments in the item, you have to transfer them from the PostedFiles to the Attachments. There is an Add method that takes a filename and a byte array. The PostedFiles collection has HttpPostedFile objects with a Stream property to retrieve the byte array.

If you do nothing they will just save into the item for you probably through the same process.

When I did this I was overriding SaveItem in the SaveButton control using RenderingTemplates.

]]>
By: Brian Bedard http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/comment-page-1/#comment-47871 Brian Bedard Sat, 20 Mar 2010 14:55:58 +0000 http://www.endusersharepoint.com/?p=5272#comment-47871 The attachments are stored in a hidden folder called Attachments on the List root folder in a subfolder named the item number. The attachment retains its filename so it's easy to retrieve through the API and maybe the Web browser. The attachments are stored in a hidden folder called Attachments on the List root folder in a subfolder named the item number. The attachment retains its filename so it’s easy to retrieve through the API and maybe the Web browser.

]]>
By: Shankar Raman http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/comment-page-1/#comment-47241 Shankar Raman Thu, 18 Mar 2010 19:14:04 +0000 http://www.endusersharepoint.com/?p=5272#comment-47241 Great Post MG- got a question for you. I am trying to create a custom application page that pretty much looks the same as the NewEditForm.aspx and adding a custom spell check to the submission process so that all the text fields can be properly spelled ( we are using WSS 3.0). I figured all of how SharePoint uses javascript to show the attachment section and add file location to the bottom of the screen. The one thing that I am not able to figure out is how do I upload the attachments using server side script to the list. Great Post MG- got a question for you. I am trying to create a custom application page that pretty much looks the same as the NewEditForm.aspx and adding a custom spell check to the submission process so that all the text fields can be properly spelled ( we are using WSS 3.0).
I figured all of how SharePoint uses javascript to show the attachment section and add file location to the bottom of the screen. The one thing that I am not able to figure out is how do I upload the attachments using server side script to the list.

]]>
By: Dan Sharpe http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/comment-page-1/#comment-41396 Dan Sharpe Fri, 05 Mar 2010 02:57:27 +0000 http://www.endusersharepoint.com/?p=5272#comment-41396 This is a great post - what I am attempting to do is not manage the upload of attachments, but instead audit who downloads the attachments which are attached to specific items in the server lists. This is a great post – what I am attempting to do is not manage the upload of attachments, but instead audit who downloads the attachments which are attached to specific items in the server lists.

]]>