Upload/Download file to/from a document library in a SharePoint online site

Hi,
I am referring to the below blog for Upload/Download file to/from a document library in a SharePoint online site.
http://blogs.msdn.com/b/rohitpuri/archive/2007/04/10/upload-download-file-to-from-wss-document-library-using-dav.aspx?CommentPosted=true#commentmessage
I would like to know if this is feasible with a SharePoint online site.
If feasible, how can I resolve the below exception I am getting while using the code.
“The remote server returned an error: (403) Forbidden”.
Thanks,
Thanan

Hi,
Actually what I am trying to achieve is the two things.
1) By using only the user's name, need to upload/download from/to the document library of SharePoint online site using the CSOM. (i.e., achieving Single Sign On / Windows Authentication)
2) I need to achieve the above only by passing the document URL; not by hardcording/ configuring the document library name in the windows application.
Can anyone pls help on this now?
[Below code is working fine. But need to arrive the solution whereas the above 2 conditions are not violated.
using (var clientContext
= new ClientContext("https://yoursiteurl.com"))
           string passWd
= "password";
           SecureString securePassWd
= new SecureString();
           foreach
(var c in passWd.ToCharArray())
                securePassWd.AppendChar(c);
            clientContext.Credentials
= new SharePointOnlineCredentials("username", securePassWd);
           using
(var fs =
new FileStream("fileName",
FileMode.Open))
var fi =
new FileInfo("fileName");
var list = clientContext.Web.Lists.GetByTitle("Doc Library");
               clientContext.Load(list.RootFolder);
               clientContext.ExecuteQuery();
var fileUrl = String.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl,
fi.Name);
Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl,
fs, true);
Thanks,
Thanann

Similar Messages

  • Not able to copying files/folders from one Document Library to another Document Library using Open with Browser functionality

    Hi All, 
    We have SharePoint Production server 2013 where users are complaining that they are not able to copy or move files from one document library to another document library using “Open with Explorer” functionality.
    We tried to activate publishing features on production server but it did not work. We users reported following errors:  
    Copying files from one document library to another document library:
    Tried to map the document libraries and still not get the error to copy files: 
    In our UAT environment we are able to copy and move folders from using “Open with Explorer” though.
    We have tried to simulate in the UAT environment but could not reproduce the production environment.  
    Any pointers about this issue would be highly appertained.
    Thanks in advance
    Regards,
    Aroh  
    Aroh Shukla

    Hi John and all,
    One the newly created web applications that we created few days back and navigated to document library, clicked on “Open with Explorer”, we get this error.
    We're having a problem opening this location in file explorer. Add this website to your trusted and try again.
    We added to the trusted site in Internet Explorer for this web application, cleared the cache and open the site with same document library but still get the same above error.
    However, another existing web application (In same the Farm) that we are troubleshooting at the moment, we are able click on “Open with Explorer”,  login in credentials opens and we entered the details we are able to open the document
    library and tried to follow these steps:
    From Windows Explorer (using with Open with Explorer), tried to copy or move a files to
    source document library.
    From Windows Explorer moved this file to another destination document library and we got this error.
    What we have to achieve is users should be able to copy files and folders using
    Open with Explorer functionality. We don’t know why Open with Explorer
    functionality not work working for our environment.  
    Are we doing something wrong? 
    We have referred to following websites.
    we hope concepts of copying / Moving files are similar as SharePoint 2010. Our production environment is SharePoint 2013.   
    http://www.mcstech.net/blog/index.cfm/2012/1/4/SharePoint-2010-Moving-Documents-Between-Libraries https://andreakalli.wordpress.com/2014/01/28/moving-or-copying-files-and-folders-in-sharepoint/
    Please advise us. Thank you.
    Regards,
    Aroh
    Aroh Shukla

  • How to upload/download file to/from server using FiledownloadUI ?

    Hi experts,
    I don't have much experience of WDABAP. I have to upload a file  to server and then download it again. I have implemented  this functionality but I am unable to view contents of .xls/.doc/.docx/.msg file only  txt file contents are properly visible. I have used  following command to upload the file:-
    OPEN DATASET fname FOR OUTPUT IN BINARY MODE.
    I had  also tried this but it is throwing  exception that it can be used only for character type data.
    OPEN DATASET fname FOR OUTPUT IN TEXT MODE  ENCODING UTF-8    WITH SMART LINEFEED.  
    Thanks in advance.
    Problem Solved!
    Regards,
    Vishesh
    Edited by: Vishesh@1986 on Sep 26, 2011 7:37 AM

    I have resolved the issue myself!!!

  • How to upload/download file into/from blob column in ADF/JDev 11g.

    Hello to all.
    I found demo from Kuba user on that page: http://kuba.zilp.pl/?id=1
    But that demo is for release 10g and too complicated for me for this time (I'm fish in Jdeveloper).
    I can create some simple table view (of form view) with oracle connection with table with blob data.
    Blob column will content doc/xls/pdf ...etc.
    Now I can add two buttons for download and upload.
    What I have to do in next time?
    Is it possible to use some component or something?
    Thank you
    Ben

    I was able to accomplish downloading from a blob, but I'm trying to dynamically set the ContentType.
    As the table may contain different types of files, I'm setting the ContentType to #{row.Fileext}, where Fileext is set in SQL select as follows:
    pseudocode: get file extension, and set the content type based on file extension.
    sql select :decode(substr(fdv.file_name,instr(fdv.file_name,'.',-1,1)+1),'log','text/plain; charset=utf-8','xml','text/xml','xls','application/vnd.ms-excel','tif','image/tiff','jpg','image/jpeg','unknown')
    I rather use a fuction/method, and tried the following instead:
    ContentType = #{backingBeanScope.backing_processReqs.FileAttachContType}
    where FileAttachContType =
    public class ProcessReqs {
    public String FileAttachContType() {
    // code to substring filename for extension and decode values
    return strContType
    But I get the following error:
    Error 500--Internal Server Error
              javax.el.PropertyNotFoundException: The class 'sunrider.reqpoportal.view.backing.ProcessReqs' does not have the property 'FileAttachContType'.
                   at javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:547)
                   at javax.el.BeanELResolver.getValue(BeanELResolver.java:249)
                   at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
    Ideas?
    PS: Kuba, I've been trying to get to your blog all day, and it would just time out.
    Thanks everyone in advance!
    -R
    Edited by: user6631964 on Jul 24, 2009 5:55 PM

  • Upload and download the file same name but different extension from the document library.

    HI,
         I am using the Client Object Model (Copy. Asmx ) To upload and download the file from the document library.
    I am having the mandatory File ID for the each Document.
    I tried to upload the the document (KIF53.txt) with File ID (KIF53) uploaded successfully.
    Again I tried to Upload the document(KIF53.docx) With File ID(KIF53) its uploaded the file but it not upload the File ID in the Column
    Please find the below screen shoot for the reference.

    thanks ashish
    tried 
    My requirement is to create the  folder and sub folder in SharePoint document library. If already exist leave it or create the new folder and the subfolder in the Document library using client side object model
    I able to check for the parent folder.
    But cant able to check the subfolder in the document library.
    How to check for  the sub folder in the document library?
    Here is the code for the folder IsFolder alredy Exist.
    private string IsFolderExist(string InputFolderName)
            string retStatus
    = false.ToString();
            try
                ClientContext context
    = newClientContext(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryLink"]));
    context.Credentials = CredentialCache.DefaultCredentials;
                List list
    = context.Web.Lists.GetByTitle(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryName"]));
                FieldCollection fields
    = list.Fields;
                CamlQuery camlQueryForItem
    = new CamlQuery();
    camlQueryForItem.ViewXml = string.Format(@"<View 
    Scope='RecursiveAll'>
    <Query>
                          <Where>
    <Eq>
    <FieldRef Name='FileDirRef'/>
    <Value Type='Text'>{0}</Value>
                            </Eq>
    </Where>
    </Query>
    </View>", @"/sites/test/hcl/"
    + InputFolderName);
    Microsoft.SharePoint.Client.ListItemCollection listItems
    = list.GetItems(camlQueryForItem);
    context.Load(listItems);
    context.ExecuteQuery();
                if (listItems.Count
    > 0)
    retStatus = true.ToString();
                else
    retStatus = false.ToString();
            catch (Exception ex)
    retStatus = "X02";
            return retStatus;
    thanks
    Sundhar 

  • Sharepoint 2010 - Archiving the files from one document library to another document library in sharepoint site

    I have a requirement to move the documents from one document library to another document library.
    Source Library - DocumentLib
    Destination Library - Archive
    Archive document library will have folders by fiscal year.
    Source documentlibrary has files from year 2012 till date.
    Archive folder will have folders by fiscal year -(fiscal year starts from July1st -June 30th )
    If the document is created date  between 1st  July 2012 -June 2013 then move the document to Archive document library and in  folder Fiscal Year 2013.
    If the document is created date  between 1st  July 2013 -June 2014 then move the document to Archive document library and in  folder Fiscal Year 2014.
    The structure of destination document library folder should be same as source document library.
    Please find attached the screenshot of the requirement.
    Files Type - Excel,pdf,microsoft outlook item
    Could we use Sharepoint designer workflow to achive this task?
    Any help on this will be appreaciated.

    Hi Asritha,
    According to your description, you want to create a workflow to meet the need.
    Per my knowledge, there is no built-in action which can move the documents from the current library to a folder in another library.
    I recommend to use the custom activity 'Copy List Item Extended' which need to be downloaded from
    http://spdactivities.codeplex.com/.
    Please per the steps below to deploy the custom activity to SharePoint:
    Download the activity form http://spdactivities.codeplex.com/
    Open Dos command prompt.
    Browse to the directory that you can access stsadm.exe. The default location in version 3.0 is C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\bin
    Type the stsadm commands: stsadm -o addsolution -filename C:\UsefulSPDWorkflowActivities_0.5.0\DP.Sharepoint.Workflow.wsp (“C:\UsefulSPDWorkflowActivities_0.5.0\” is the file path)
    Type the stsadm commands: stsadm -o deploysolution -name DP.Sharepoint.Workflow.wsp -allowgacdeployment -force -immediate 
    Open the Center Administration, Click System Setting->Manage Farm Solution-> dp.sharepoint.workflow.wsp->Deploy to the Web Application.
    After that, we can create a workflow to meet the need.
    Here is the detailed steps to create the workflow:
    Create a workflow associated with the Source Library DocumentLib and set the workflow to start when an item is created.
    Select If current item field equals value, change the settings to be If Current Item: Created is greater than 7/1/2012.
    Select If current item field equals value, change the settings to be If Current Item: Created is less than 6/30/2013.
    Select Copy List Item Extended, change the settings to be Copy item in Current Item to list at Fiscal Year 2013 folder url.
    Select Delete Item, change the settings to be Delete Item in Current Item.
    Select If current item field equals value, change the settings to be If Current Item: Created is greater than 7/1/2013.
    Select If current item field equals value, change the settings to be If Current Item: Created is less than 6/30/2014.
    Select Copy List Item Extended, change the settings to be Copy item in Current Item to list at Fiscal Year 2014 folder url.
    Select Delete Item, change the settings to be Delete Item in Current Item.
    Publish the workflow.
    Best regards.
    Thanks

  • Having trouble opening Crystal Report files from a document library

    I am trying to open Crystal Report .rpt files from a document library in either the native, client Crystal Reports software or in Crystal Reports Viewer. When I add the Crystal Report files to a document library and attempt to open them SharePoint displays
    a prompt asking me to save the file locally instead of opening the file. I have done a lot of research online and found several sites discussing similar scenarios, however, I have not been able to get these solutions to work. Here is a short list of sites
    I have referenced for possible solutions:
    http://naadydev.blogspot.com/2013/03/crystal-report-viewer-sharepoint-2010.html?showComment=1383339860122
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/52aabf2d-10dc-424c-bd50-124fc972a9b9/crystal-report-viewer-integration-with-sharepoint-2010?forum=sharepointgeneralprevious
    http://www.codeproject.com/Articles/42731/Crystal-Reports-WebPart-for-SharePoint
    Here are the steps I have done to try to get the .rpt files to open:
    Added the Crystal Report extension .rpt as a MIME type
    Installed the Visual Studio 2012 Crystal Reports Viewer toolbar
    Installed the 64-bit Crystal Reports runtime
    I have also created a solution file based off the Code Project site which partially works, but not quite right. In this project I have created a document library called "Crystal Reports rpt Files" and deployed the solution file to a site. When
    I open the Web Part Maintenance Toolbar I can see the selected .rpt file in the drop-down, but no Crystal Report file is displayed on the page itself.
    I am not sure what I am doing wrong. Does anyone have experience working with Crystal Reports and SharePoint 2013 (or earlier versions) that could lend some advice?
    Thank you,
    Alex

    We are having the exact same issue, has anyone resolved this yet?

  • Restrict download of documents from a Document library

    Hi,
    I am working on a trial version of SharePoint online E3. I enabled IRM on it with a hope that it will restrict "DOWNLOAD" of documents from a document library itself. However to my bad, it seems it allows downloading... with imposed restrictions. 
    Can anybody help me in this? I need only some of the users to be able to download/print/copy documents from library and NOT all of them. Rest can only view the document. Is it possible in SP Online? 
    Is it possible in SharePoint 2010 or is it the same in here as well?

    Hi 
    yes,sharepoint online we can Use IRM. please refer yes, 
    http://office.microsoft.com/en-in/office365-sharepoint-online-enterprise-help/set-up-information-rights-management-irm-in-sharepoint-admin-center-HA102895193.aspx
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • Firefox crashes when uploading/downloading files from/to 'desktop folder'

    Hello
    I'm hoping, that you can help me!
    I'm using Firefox 28.0 on MacBook Pro Mavericks 10.9.2
    Firefox crashes/freezes when I try to upload/download files from/to my 'desktop folder'.
    I't only happens, when I use this folder. Download to 'download folder' or any other folder works fine.
    Download to 'desktop folder' when using Safari also works fine.
    I't only happens when desktop and firefox tries to communicate.
    It's very annoying when I accidentally forget, that the bugs is there, and I have to force quit and start all over again. And sometimes I don't even have a choice, because 'desktop' randomly opens as default folder, when I try to upload things.
    Thank you so much in advance!
    Kind regards Elizabeth

    Hi ESwan,
    I am not a Mac user so not the best person to attempt to assist but here goes.
    I am presuming that info such as
    PID: 1695 Event: cpu usage (microstackshots only)
    Relate to the Mac OS X crash & event logging and reporting.
    What we need are the ones that Firefox itself generates and submits for processing by Mozilla Firefox
    * See [[Firefox crashes - Troubleshoot, prevent and get help fixing crashes#w_get-help-fixing-this-crash]]'''#w_get-help-fixing-this-crash'''
    From what you say the crashes occur after a certain action and I am hoping that you will be able to use the easy method as in the article linked above. Navigate to about:crashes by keying ''about:crashes'' into the address bar. You are loolking for the ones starting wth ''bp-'' Paste two or three of those into your next post. Include the bp- part but not any link information before that. After they are pasted into the forum the forum software changed them to be links.

  • The way SharePoint open office documents will differ if the user try to open them from the document library directly, or if users try to open the document from the search result page.

    I have a document library where I have uploaded an excel sheet to it. Now If I click on the excel sheet directly from the document library page , I will get the following error ““The webpage cannot be displayed””. While if I do a search and I open the excel
    sheet from the search result page , it will open the excel sheet using the excel services inside the browser !!.
    So can anyone advice on this ?
    Also if I have a PowerPoint document , and I try to open it from the document library I will get the following error “The webpage cannot be displayed” , and the URL will be prefix with the following “ms-powerpoint:ofv|u|”. while if i do a search and i open
    the PowerPoint from the search result page i will be prompted to either open or save the document ? So why SharePoint is reacting totally different when trying to open document library items from the document library Or from the search result page?

    Hi,
    The behavior in the document library could be probably because of the Documents handling setting. Please try setting it to default behavior (Open in browser) as i hear from you that the default behavior is to open from browser.
    Thanks, Suneetha
    Currently I have set the following;-
    1. On the library advance setting :- I define  “Open in the client application”
    2. On the web application setting:- I define stricked for Browser File Handling
    And I have noted if I delete the browser cache and I access the document , then I will be prompted with the download dialog. but if I re-click on the same document I will be redirected to the
    The webpage cannot be displayed
    And the ms-powerpoint:ofv|u| will be added to the beginning of the URL. So could this be a caching problem ?

  • HT1349 When I try to download an audiobook from my library I get a message saying it has not been copied because it cannot be played on this ipod?  Any ideas why this might be I've just downloaded another audiobook from the same library?

    When I try to download an audiobook from my iTunes Library I get the message that 'it was not copied because it cannot be played on this iPod.  I had just downloaded another audio book from the same library to the same iPad so don't know what the problem is?  maxabw

    brackenfromrincon wrote:
    Is it something about "I Shot the Sheriff" that my iPod has a moral disagreement with? It had no issue importing and installing Body Count's "Kop Killa"...
    Not really likely, is it?
    First of all, look on the iPod to see if the song is actually on there. (The last Sync of my Classic resulted in "song not copied... because it cannot be found." The song had previously been on the iPod. I checked and despite the fact that iTunes could not find the file, the song was still on my iPod. I checked the folder and the song was exactly where t was supposed to be. So I simply set iTunes to find it again. What happened? I don't know, iTunes simply threw a wobbly!)
    Second, try another Sync. Does this change anything? If the song was on the iPod, does a second Sync remove the message?  If the song was not on the iPod after the first Sync, does the second one put it on there?
    What happens?

  • How do document permissions differ from its document library and a content roll-up webpart?

    I have an excel spreadsheet (a group schedule), in a document folder, on a page that only IT management can see/access/edit, in a site that all IT group members have access to.
         for example: http://IT Group site/IT Management Page/Schedule/2015.xlsx
    On the group's homepage, I have a content roll-up web part that displays all document library contents in the group site.
    IT management consists of 3 people. They can all edit the spreadsheet from the original location, but when they access the document from the content roll-up web part on the group's homepage, they cannot save any changes.
         Accessing the file from here: http://IT Group site - content roll-up web part link "2015.xlsx" points to "IT Group site/IT Management Page/Schedule/2015.xlsx"
    The error received says "'http://IT Group site/IT Management Page/Schedule/2015.xlsx' is read-only. To save a copy, click OK, then give the workbook a new name in the Save As dialog box."
    Where would the permission issue be?
    As the SharePoint site owner, I can access the file without any problems saving from either location. Also, I created an IT Management group that has full control over the IT Group site/IT Management Page, and full control over the IT Group site.
    Thanks for any info you can share.
    Stephanie

    Thanks Cameron -
    I have no special settings on the document library where the schedule is saved. No content approval necessary or different permissions. The library is set to open documents in client application, and check-in, check out is not activated.
    I have logged in to one of their computers. They can access the spreadsheet directly from the document library and make changes freely, and save that version directly to the server, but not from any web parts. Just to test, I created a summary link web part
    on the same page that lists the document library, created a link to the file, and the file opens, but they cannot save any changes without renaming the file. The only place they can truly edit the spreadsheet without renaming is from the document library
    directly.

  • I can't upload or import videos from my iphoto library, into final cut pro x.  When i click, IMPORT MEDIA in FCP, It lists iPhoto Library as GRAY, and will not let me access it.  I need the videos out of there.  I have tried every way I can think of.

    Like the title says...
    I can't upload or import videos from my iphoto library, into final cut pro x.  When i click, IMPORT MEDIA in FCP, It lists 'iPhoto Library' as GRAY, and will not let me select it.  I need the videos out of there.  I have tried every way I can think of.
    I have also tried from the iphoto side, to export the videos or share them to final cut.  I have had no luck.
    I have tried to drag and drop indidual video clips from iphoto to fcp, and the programs simply do not respond to each other
    I can see in the OLDER version of final cut pro x, where it has IMPORT FILES as an option, it was possible.  I see this on forums and youtube videos of the older versions.
    However, the newer version that i have, does not have IMPORT 'FILES' as an option, it is simply all lumped together as IMPORT 'MEDIA'
    Thank You for the Help

    at the end, you say "import preferences", which program are you describing?
    So im safer using footage that is remotely being pulled from iphoto...
    vs
    using footage that is imported into FCP from imovie?
    Is there anything i can do in fcp to make this footage more reliable or safer or more stable as i pull remotely from iphoto?
    All the footage, and all the libraries to all programs, or on a new pegasus 12tb raid 5 setup fyi.

  • How can I copy documents from a Sharepoint On Premises library to a Sharepoint Online library and at the same time preserving their metadata?

    How can I copy documents from a Sharepoint On Premises library to a Sharepoint Online library and at the same time preserving their metadata?
    I use the Open Explorer Windows to drag and drop the files, but the metadata are not copied. Thanks.

    To maintain the metadata you'll need to use one of the third party tools that does this kind of migration.  Metalogix has a product with a free trial that we have used before.  (Don't remember whether the free version maintains metadata or not).
     You can read about it here:
    http://www.metalogix.com/Products/Content-Matrix.aspx
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • How to extract audit log data from every document library in site collection using powershell?

    Hi All,
    I have n number of document library in one site collection,
    My query is- How to extract audit log data from every document library in a site collection using powershell?
    Please give solution as soon as possible?

    Hi inguru,
    For SharePoint audit log data, These data combine together in site collection. So there is no easy way to extract audit log data for document library.
    As a workaround, you can export the site collection audit log data to a CSV file using PowerShell Command, then you can filter the document library audit log data in Excel.
    More information:
    SharePoint 2007 \ 2010 – PowerShell script to get SharePoint audit information:
    http://sharepointhivehints.wordpress.com/2014/04/30/sharepoint-2007-2010-powershell-script-to-get-sharepoint-audit-information/
    Best Regards
    Zhengyu Guo
    TechNet Community Support

Maybe you are looking for