How add file is document of sharepoint use the webpart

Hi all.
I want file upaload in sharepoint's document use my Webpart.
this is my source
protected void Button1_Click(object sender, EventArgs e)
            using (SPSite site = new SPSite("http://nar-cla500s3:12345/sites/qa"))
                using (SPWeb web = site.AllWebs[""])
                    string filepath = @"C:\Users\lx13040020\Desktop\test.xlsx";            
                    FileStream filestream = File.OpenRead(filepath); <-- error access denied
                    SPFile file = web.Folders["QADocument"].Files.Add(filepath, filestream, true);                
But I have error "access denied".
I referd to this link
(SPFile ex)
http://stackoverflow.com/questions/468469/how-do-you-upload-a-file-to-a-document-library-in-sharepoint
(Filestream Access denied)
http://stackoverflow.com/questions/7706467/access-to-the-path-denied-error-in-c-sharp
But i could not solve my problem.
please teach me, Wait for your help. Thank you

hi
I assume that in site.AllWebs[""] in your real code you use correct site-relative url of the SPWeb? If yes, then you need to ensure that account under which code is executed has access to the "C:\Users\lx13040020\Desktop" folder. The simplest way to do it
to execute your code under SPSecurity.RunWithElevatedPriveleges() (in this case you will know that code is executed under account of application pool) and give permissions to account of application pool for the mentioned path:
protected void Button1_Click(object sender, EventArgs e)
SPSecurity.RunWithElevatedPriveleges(() =>
using (SPSite site = new SPSite("http://nar-cla500s3:12345/sites/qa/test"))
using (SPWeb web = site.OpenWeb())
string filepath = @"C:\Users\lx13040020\Desktop\test.xlsx";
FileStream filestream = File.OpenRead(filepath); <-- error access denied
SPFile file = web.Folders["QADocument"].Files.Add(filepath, filestream, true);
Note that in this example I used SPWeb url in constructor of SPSite object and then SPSite.OpenWeb() which will give the same result.
Blog - http://sadomovalex.blogspot.com
Dynamic CAML queries via C# - http://camlex.codeplex.com

Similar Messages

  • HT1473 Help I just moved my music files to a external hard drive and am using the new crappy version ( i know my opinion) of itunes and cant add the files to my libray it gives me the add file to library option but not the add folder to library option wha

    Help I just moved my music files to a external hard drive and am using the new crappy version ( i know my opinion) of itunes and cant add the files to my libray it gives me the add file to library option but not the add folder to library option what am i doing wrong?

    In iTunes 11 uncheck the preferences setting in in the iTunes Preferences panel "Advanced > Copy Files to iTunes Media folder when adding to Library"

  • HT201596 80 % of my itunes files are located on a 3tb external drives; the remainder on a 4TB drive. ALL my files are on the 4TB. How do i get iTunes just to use the files on the 4tb drive so I can use the 3tb for other purposes   THX  .

    Hi,  80 % of my itunes files are located on a 3tb external drives; the remainder on a 4TB drive as I ran pout of space. ALL my files are on copied on to the 4TB drive . How do I get iTunes just to use the files on the 4tb drive so I can use the 3tb for other purposes   THX  .

    Select the desired location in preferences, then consolidate the media files to it.
    iTunes 12 for Mac: Change where your iTunes files are stored - http://support.apple.com/kb/PH19507 - Unfortunately this is misnamed.  It should say "Change where your media files but not where your library files are stored" - more information at: https://discussions.apple.com/message/22026652#22026652 - and steps 5-8 in https://discussions.apple.com/message/24491967#24491967

  • Before lollypop upgrade I could transfer files from LGg3 to computer using the LG supplied USB cord. How do I fix this bug?

    Before lollypop upgrade I could transfer files from LGg3 to computer using the LG supplied USB cord. How do I fix this bug?

    Is the G3 not recognized by the PC?  Or is it recognized and you don't see the ext SD card?  Are you able to use the Wireless Storage feature to transfer?  Do you have updated USB drivers from the LG support site?

  • How can i plot a histogram with using the results of Line Length

    PLS HELP.How can i prepare a histogram with using the results of line length code(It is somewhere in the middle).
    This is a final exam take-home question. I would appreciate if you can help?
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    import java.text.*;
    import java.io.File;
    public class WordAnalyser extends JFrame implements ActionListener
    private JMenuItem jmiAc, jmiSil, jmiCikis, jmiAnaliz, jmiHakkinda, jmiKullanim;
    private JTextArea jta1, jta2;
    private JFileChooser jFileChooser = new JFileChooser();
    File hafizada;
    File aktarilan = new File("Sonuc.txt");
    // Main method
    public static void main(String[] args)
    WordAnalyser frame = new WordAnalyser(); /* Ana ekran olusturulur */
    frame.setSize(400, 300); /* Degerleri belirlenir */
    frame.setVisible(true); /* Gorunebilirligi ayarlanir */
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public WordAnalyser()
    setTitle("Serkan Ozgen Dosya Inceleme Programina Hos Geldiniz");
    JMenuBar mb = new JMenuBar();
    setJMenuBar(mb);
    JMenu fileMenu = new JMenu("Dosya");
    fileMenu.setMnemonic('F');
    mb.add(fileMenu);
    JMenu helpMenu = new JMenu("Degerlendirme");
    helpMenu.setMnemonic('H');
    mb.add(helpMenu);
    JMenu kullanimMenu = new JMenu("Kullanim Kilavuzu");
    mb.add(kullanimMenu);     
    fileMenu.add(jmiAc = new JMenuItem("Ac", 'A'));
    fileMenu.add(jmiSil = new JMenuItem("Sil", 'S'));
    fileMenu.add(jmiCikis = new JMenuItem("Cikis", 'C'));
    helpMenu.add(jmiAnaliz = new JMenuItem("Analiz", 'D'));
    helpMenu.add(jmiHakkinda = new JMenuItem("Hakkinda", 'H'));
    kullanimMenu.add(jmiKullanim = new JMenuItem("Kullanim"));     
    getContentPane().add(new JScrollPane(jta1 = new JTextArea()), BorderLayout.CENTER);
    getContentPane().add(jta2 = new JTextArea(), BorderLayout.SOUTH);
    jmiAc.addActionListener(this);
    jmiSil.addActionListener(this);
    jmiCikis.addActionListener(this);
    jmiAnaliz.addActionListener(this);
    jmiHakkinda.addActionListener(this);
    jmiKullanim.addActionListener(this);
    public void actionPerformed(ActionEvent e)
    String actionCommand = e.getActionCommand();
    if (e.getSource() instanceof JMenuItem)
    if ("Ac".equals(actionCommand))
    Ac();
    else if ("Sil".equals(actionCommand))
    Sil();
    else if ("Cikis".equals(actionCommand))
    System.exit(0);
    else if ("Analiz".equals(actionCommand))
    sayim();
    else if ("Hakkinda".equals(actionCommand))
    JOptionPane.showMessageDialog(this,
    "!!!! Bu program text analizi gerceklestirir. Her hakki saklidir SERKAN OZGEN!!!!",
    "Bu program hakkinda",
    JOptionPane.INFORMATION_MESSAGE);
    else if ("Kullanim".equals(actionCommand))
         JOptionPane.showMessageDialog(this,
         " Ilk once dosya menusunden Ac i tiklayarak analiz etmek istediginiz Dosyayi seciniz (Lutfen uzantisi *.txt \nveya *.log olsun). Daha sonra Degerlendirme menusunden analizi tiklarsaniz dosyanizda kac adet rakam, harf, \ncumle ve kelime oldugunu gorebilirsiniz. Simdiden kolay gelsin",
         "Programin kullanim detaylari",
         JOptionPane.INFORMATION_MESSAGE);
    private void Ac()
    if (jFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
    hafizada = jFileChooser.getSelectedFile();
    Ac(hafizada);
    // Acilan Dosyayi ana ekranda gostermeye yariyan bir method
    private void Ac(File file)
    try
    // Acilan dosyayi okuma ve ana ekranda gosterme
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
    byte[] b = new byte[in.available()];
    in.read(b, 0, b.length);
    jta1.append(new String(b, 0, b.length));
    in.close();
    catch (IOException ex)
    // Temizle tusunun hangi ekranlara etki edecegini secme
    private void Sil()
    jta1.setText("");
    jta2.setText("");
    private void sayim()
    int buff;
    int sayac = 0;
    int Cumleler = 0;
    int Kelimeler = 0;
    int Karakterler = 0;
    int Satirlar = 0;
    int Rakamlar = 0;     
    boolean start = true;
    int linenum = 0;     
    try
    FileInputStream instream = new FileInputStream(hafizada);
    FileOutputStream outstream = new FileOutputStream(aktarilan);
         BufferedReader infile = new BufferedReader(new InputStreamReader(new FileInputStream(hafizada)));
    PrintStream out = new PrintStream(outstream);
         out.println("---Kelime Avcisinin Sonuclari---");
         String line = infile.readLine();
         while (line != null){
         int len = line.length();
         linenum++;
         line = infile.readLine();
         out.println("Line Length :"     + linenum + "\t" +len);
    while ((buff=instream.read()) != -1)
    switch((char)buff)
    case '?': case '.': case '!': /* Eger "?", "." veya "!" gorurse program cumleleri ve kelimeleri arttirir*/
    if (start == false)
    Cumleler++;
    Kelimeler++;
    start = true;
    break;
    case ' ': case '\t': case ',': case ';': case ':': case'\"': case'\'': /* Eger /t,;:\ ve \" bu isarteleri goruruse program kelimeleri arttirir */
    if (start == false)
    Kelimeler++;
    start = true;
    break;
              case 'n': case '\n': /* Eger \n gorurse satirlari arttirir */
              if (start == false)
                   Satirlar++;
                   Kelimeler++;
                   start = true;
              break;
    default:
    if (((char)buff >= 'a' && (char)buff<='z')|| /*a-z, A-Z veya - degerlerini gorurse karakterler arttirilir */
    ((char)buff >= 'A' && (char)buff<='Z')||
    ((char)buff == '-'))
    Karakterler++;
    if ((Kelimeler % 50) == 49)
    if (start == true)
                   out.println();     
    out.print((Kelimeler+1) + " ");
    out.print((char)buff);
    start = false;
              if ((char)buff >='0' && (char)buff <='9') {  /* 0-9 gorurse rakamlari arttiri */
                   Rakamlar++; }
    }// switch
         }//while
    instream.close();
    out.println();
    out.println();
    out.println("Karakter sayisi: " + Karakterler);
         out.println("Kelime sayisi: " + Kelimeler);
    out.println("Cumle sayisi: " + Cumleler);
         out.println("Satir sayisi: "+ Satirlar);
         out.println("Rakam sayisi: "+ Rakamlar);
    outstream.close();
    try
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(aktarilan));
    byte[] b = new byte[in.available()];
    in.read(b, 0, b.length);
    jta2.append(new String(b, 0, b.length));
    in.close();
    catch (IOException ex)
    catch (Exception e)
    System.out.println(e);
    }

    Why is it that you're not interested in IOExceptions?
    catch (IOException ex)
    } Empty catch blocks is a hallmark of foolish Java code. At least print out the stack trace.
    %

  • I am trying to get space on an external hard drive which has some old time machine back up files that I do not need but can not eliminate, even by going into the time machine, clicking on the backup file to be eliminated and using the drop down eliminate

    I am trying to get space on an external hard drive which has some old time machine back up files that I do not need but can not eliminate, even by going into the time machine, clicking on the backup file to be eliminated and using the drop down menu with the gear box symbol to eliminate

    I cannot find this 300GB "Backup" in the Finder, only in the Storage info when I check "About This Mac".
    You are probably using Time Machine to backup your MacBook Pro, right? Then the additional 300 GB could be local Time Machine snapshots.  Time Machine will write the hourly backups to the free space on your hard disk, if the backup drive is temporarily not connected. You do not see these local backups in the Finder, and MacOS will delete them, when you make a regular backup to Time Machine, or when you need the space for other data.
    See Pondini's page for more explanation:   What are Local Snapshots?   http://pondini.org/TM/FAQ.html
    I have restarted my computer, but the information remains the same. How do I reclaim the use of the 300GB? Why is it showing up as "Backups" when it used to indicate "Photos"? Are my photos safe on the external drive?
    You have tested the library on the external drive, and so your photos are save there.  
    The local TimeMachine snapshot probably now contains a backup of the moved library.  Try, if connecting your Time Machine drive will reduce the size of your local Time Machine snapshots.

  • How to suppress Save As dialog when using the Close button on an editable pdf

    Environment: Windows 7, SDK 9, Adobe Acrobat Pro X, Visual Studio 2010 Professional
    Summary: when a document is opened for editing using automation, edited, then closed using the "Close" button, the confirmation dialog appears, "yes" is selected and then the "Save As" dialog appears.  It should save without the "Save As" dialog in the same way it does were the document opened from Adobe Acrobat directly.  My question is, is there any flag to set which governs whether the "Save As" dialog appears as part of the close document process.  It is behaving as if the document is read-only upon close. (it isn't)
    This is how the document is opened from C++:
    if(SUCCEEDED(hr = ::CoCreateInstance(__uuidof(Adobe9::Acrobat::CAcroAVDoc), 0, CLSCTX_ALL, IID_IUnknown, (void**)&pUnk))){
    hr = OleRun(pUnk);
    if (SUCCEEDED(hr)){
    if (SUCCEEDED(hr = pUnk->QueryInterface(&pAVDoc))){
    hr = pAVDoc->Open((BSTR)CComBSTR(strPath), strDocName, &bRet);
    Even when the plugin is removed from the plug_ins\AcrobatSDK directory, the behaviour is the same.
    Another reproduction is running the BasicIacVC sample, commenting out all lines from gAcroPdDoc->Close(); in InitInstance() and returning TRUE.  If an editable document is opened using the sample, edited then closed using the "X" button, the confirmation dialog is followed by a "Save As" dialog as if it were a read-only document which it is not.
    Any suggestions would be appreciated.
    Regards,
    Evan

    Yes, it does.  (as long as the pdf has been opened via a COM interface)

  • How can I connect personal hotspot to use the internet from my phone on my laptop?

    I do not have internet at home and want to be able to connect using the personal hotspot on my phone. How do i do this??

    How much would be a month?
           From: Verizon Wireless Customer Support <[email protected]>
    To: kelly johnson <[email protected]>
    Sent: Wednesday, October 8, 2014 12:02 PM
    Subject:  - How can I connect personal hotspot to use the internet from my phone on my laptop?
    #yiv3595356488 img
    |  
    |
      | 
    A message from the Verizon Wireless Community
      |
    |   |
    How can I connect personal hotspot to use the internet from my phone on my laptop?
    created by Verizon Wireless Customer Support in iPhone 4S - View the full discussion                  Hello kmj65
    Thanks for replying. The plan you have it would be an additional charge to add the hotspot feature. It's not free with the Nationwide plan. You would need to add the feature online at www.verizonwireless.com/myverizon
    JoeL_VZW
    Follow us on Twitter @VZWSupport   Reply to this message by replying to this email -or- go to the message on Verizon Wireless Community Start a new discussion in iPhone 4S by email or at Verizon Wireless Community


    © 2014 Verizon Wireless
    Verizon Wireless
    One Verizon Way
    Mail Code: 180WVB
    Basking Ridge, NJ 07920
    Not interested in these emails anymore, or want to change how often they come? Update your email preferences by visiting https://community.verizonwireless.com/user-preferences!input.jspa.
      |
    We respect your privacy. Please review our privacy policy for more information
    about click activity with Verizon Wireless and links included in this email.
      |

    |

  • How do I turn off suggested videos using the YouTube widget?

    How do I turn off suggested videos using the YouTube widget?

    That's not currently an option in the Muse youtube widget.
    We'll add support for that option in a future release of Muse.

  • I currently have a mac osx, and my CC keeps coming saying its expired, when it should be running the CS6 design standard.  So how do I get my platform to use the CS6 as my default instead of the CC one.

    I currently have a mac osx, and my CC keeps coming saying its expired, when it should be running the CS6 design standard.  So how do I get my platform to use the CS6 as my default instead of the CC one.

    Sign in, activation, or connection errors | CS5.5 and later
    And you can change the default program for a file type under File --> Info.
    Mylenium

  • In iPhoto, how can I find a particular event using the search function?, In iPhoto, how can I find a particular event using the search function?

    In iPhoto, how can I find a particular event using the search function?

    NO - read my last answer over a year ago
    That is because iPhoto is all about photos - not about files
    You do not access the piles in iphoto - you access the photos using either iPhoto or the media browser - see this user tip for photo access details
    LN

  • How do I make document relative links for the site?

    How do I make document
    relative links for the site -
    <img src="../images/foo.gif"... (for example)?

    > How do I make document
    > relative links for the site -
    look in the bottom of the "browse to file" dialog box.
    Alan
    Adobe Community Expert, dreamweaver
    http://www.adobe.com/communities/experts/

  • I used to be able to send document as a PDF or Word Document via email using the toolbar.

    I used to be able to send Pages documents as a PDF or Word Document via email using the Pages toolbar (not the iWork feature).  Lately, it hasn't been working at all.  No email pops up; just nothing.  Is anyone else having this problem?  Any solutions?  I'm running Pages '09 version 4.1.

    This Apple Express Helper is a dumb one.
    File names with # and $ are perfectly treated by the share to Mail feature.
    What is rejected is the slash (/) and it's perfectly normal.
    Since the delivery of the first version of OS X, slash is an illegal character in file names.
    Apple thought that it would be fair to build a piece of code taking care of such chars because they were valid ones in the older operating systems.
    But they expected that users will drop these chars. Alas they didn't and users like you are continuing to play with matches.
    At last, OS X 10.7 removed the extraneous code and now, hosanna, iWork refuse to export files whose name contain the infamous slash.
    Yvan KOENIG (VALLAURIS, France) lundi 9 avril 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.3
    My Box account  is : http://www.box.com/s/00qnssoyeq2xvc22ra4k

  • How to sync 2 different Mac users using the same Apple ID and with out mixing each other info?

    How to sync 2 different Mac users using the same Apple ID and with out mixing each other info?
    We are two people using three difrent Macs, 1 Iphone and 1 Ipad with separate USERS  on each Mac but sharing the same Apple ID: xxxxxx
    I set up the first user to iCloud and it was OK but when I set up the second user to use iCoud the first users's info gets mixed with the second user's info?
    Do we have to set up a diffrent Apple ID for each other?
    Sometime ago I added my friends E mail (yyyyy) to the main Apple ID (xxxx) as for using his E mail account (to separate our e mail accounts, and it's working ok) but now when I try to create a new apple ID whith the same friend's e mail (yyyyyy)  it says that his mail (yyyyy) is already an apple ID when the Apple ID is really my E mail (xxxxx)... any clue?
    Thanks

    I believe because you migrated from a Nokia to an iPhone you need to register the Bn phone number with your Apple ID so it can be used for iMessage. The Pn number seems to be the only one registered
    Go here > https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/
    Manage your Apple ID and see if that does the trick
    Hope that helps

  • How can i create multiple accounts but use the same itunes?

    how can i create multiple accounts but use the same itunes?

    Hi iCloud is Making Me Go Crazy,
    You will need to create a new Apple ID for your GameCenter and iCloud services.  You can continue to use the current Apple ID you share with your Mom for access to iTunes Store purchases if you wish. 
    Using your Apple ID for Apple services
    http://support.apple.com/kb/HT4895
    Frequently asked questions about Apple ID
    http://support.apple.com/kb/HT5622
    Cheers,
    - Judy

Maybe you are looking for

  • Changing default command mode to Privileged EXEC

    I am currently setting up a 2800 Series router, and prefer a username/password type authentication rather than a single enable password. To do this, I did: Router(config)# username <myuser> privilege 15 secret 0 <mypassword> Router(config)# username2

  • Apple mail multiple copies in trash

    With Apple Mail on my macbook pro I have multiple copies of a deleted mail appearing in the trash. This just started. How can I stop this?

  • Mavericks 10.9.5 update and Quicktime

    After i updated my iMac from OSX 10.9.4 to .5 yesterday, .mv4 clips no longer open in Quicktime 10 or 7 Player. I have over a hundred of clips in this format that I use in language teaching. They still open in VLC and when imported into iTunes, but n

  • Installing Leopard and Tiger on the same computer ...

    Hi, How could I install both system, Leopard and Tiger, on my iMac G5 giving me the possibility to startup from one of them at a time ... I want this to have this possibility to run occasionally classic (with Tiger) while using mainly Leopard. Is thi

  • G4 out of Disk space.

    Equipment used: One G4 MDD 160 GB Internal hard drive & a 250GB exterior hard drive. Every thing worked fine(internal drive had 25GB of unused space and I backed up to the external drive. After several weeks my internal drive said I was out of unused