0

Right now, i know how to check in word documents in sharepoint site. Now, i need to check in for jpg or pdf files. Does anyone know how and if it's even better, provide for me codes to implement this. Thank you.

  [WebMethod(EnableSession = true, Description = "Typical Web Method")]
    public string CheckoutFile(string url)
    {
        try
        {
            //url = "http://it3127:30091/Shared%20Documents/Folder1/Testing%20new%20document.docx";
            SPSite site = new SPSite(url);
            SPWeb oWebsite = site.OpenWeb();
            //SPFolder oFolder = oWebsite.Folders["Shared Documents"];
            //SPFileCollection collFiles = oFolder.Files;

            SPFile file = oWebsite.GetFile(url);
            file.CheckOut();
        }
        catch (Exception ex)
        {
            return "false";
        }
        return "true";
    }
  • It should be no real difference, can you show us your code sp we can see where it goes wrong? :) – Robert Lindgren Oct 28 '13 at 7:52
  • @RobertLindgren hi robert. i do not have the codes for check in as it is already a built-in for Outlook 2010. Also, i have set the settings in SharePoint to require check-in. So i just nid to checkout it. My Checkout codes is on top. – kyrul Oct 28 '13 at 9:33
1
 private void publishItemStyle(string url)
 {
     SPSite site = new SPSite(url);
     SPWeb oWebsite = site.OpenWeb();

     try
     {
         SPFile file = web.GetFile("Style Library/Xsl Style Sheets/ItemStyle.xsl");

         if (file.Level == SPFileLevel.Checkout)
             file.CheckIn("", SPCheckinType.MajorCheckIn);
         if (file.Level == SPFileLevel.Draft)
         {
             if (file.DocumentLibrary.EnableModeration) file.Approve("");
             else file.Publish("");
         }
        file.Update();
     }
     catch (Exception e)
     {
         // Some logging
     }
     finally{
         oWebsite.Dispose();
         site.Dispose();
     }
}

Modified example from here http://jeff-sharepoint-note.blogspot.se/2011/07/publish-and-approve-file.html

Can easily be improved with using statements for SPSite and SPSite instead

  • 1
    Also, if you use this method exactly, watch for concurrency bugs - you could be modifying the file outside this method, using another instance of SPSite, then call this method and attempt to save 'changes' to a file handle that isn't associated to the SPSite instance created here. – James Love Oct 28 '13 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.