Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Discussions

venkatzeus venkatzeus
  • Creating pdf file using C# causes "Adobe reader cannot open file" error

    Hi,

    There really is a first time for everything. you dont really learn everything the time you start working. It is through mistakes that you learn. I got "iText" now. will try it using that.

  • Creating pdf file using C# causes "Adobe reader cannot open file" error

    Hi,

    I am using VS 2010 and C#. I am trying to create a pdf file in web application.

    I am trying to convert a dataset to pdf file. The pdf file is getting generated, but when i try to open the pdf, i am getting the error as "Adobe reader could not open "sample.pdf" because it is either not a supported file type or because the file has been damaged"

    I have tried with "application/pdf" as well as "application/octet-stream". Both are giving the same error.

    How to fix this?

    Thank you

  • Moss 2007 - Activated Feature working only for Admin Account

    Hi,

    Thank you very much the reply.

    Is there any solution you could suggest to correct that behavior.

    Thank you

  • Moss 2007 - Activated Feature working only for Admin Account

    Hi,

    Thank you very much for the reply. I understand that I should have used WSPBuilder. I would download it and start working with it as you mentioned.

    I checked the blog and changed code to below:

        public static class SpSecurityHelper
        {
            public static SPSite GetElevatedSite(SPSite theSite)
            {
                SPUserToken sysToken = GetSystemToken(theSite);
                return new SPSite(theSite.ID, sysToken);
            }
    
            public static SPUserToken GetSystemToken(SPSite site)
            {
                site.CatchAccessDeniedException = false;
                try
                {
                    return site.SystemAccount.UserToken;
                }
                catch (UnauthorizedAccessException)
                {               
                    SPUserToken sysToken = null;
                
                    SPSecurity.RunWithElevatedPrivileges(
                    delegate()
                    {
                        using (SPSite lolcatKiller = new SPSite(site.ID))
                        {
                            sysToken = lolcatKiller.SystemAccount.UserToken;                    
                        }
                    }
                    );
                    return sysToken;
                }
            }
        } 
    
    
      public class ItemCounting : SPItemEventReceiver
        {
            public override void ItemAdded(SPItemEventProperties properties)
            {
                base.ItemAdded(properties);
                GetOpenItems();
            }
    
    public override void ItemDeleted(SPItemEventProperties properties)
            {
                base.ItemDeleted(properties);
                GetOpenItems();
            }
    
    
    public static void GetOpenItems()
      {
    using (SPSite site = SpSecurityHelper.GetElevatedSite(new SPSite(Constants.url)))
      {
    using (SPWeb currentweb = site.OpenWeb())
      {
    SPListCollection mylists = currentweb.GetListsOfType(SPBaseType.DocumentLibrary);
    for (int q = mylists.Count - 1; q >= 0; q--)                           
    {
    SPList list = mylists[q];
    
    if (!list.Hidden)
    {                              
    currentweb.AllowUnsafeUpdates = true;
    SPFolder folder = list.RootFolder;
    SPView curview = list.DefaultView;
    SPViewFieldCollection fieldCol = curview.ViewFields;
    if (!fieldCol.Exists("FilesCount"))
    {
    AddField("FilesCount", SPFieldType.Text, list.Fields);
    fieldCol.View.DefaultView = true;                                      
    curview.ViewFields.Add("FilesCount");
    curview.Update();                                  
    }
                                               
    int jouas = 0;                              
    if (folder != null && folder.Name.CompareTo("Forms") != 0)
    {
       foreach (SPFolder subFolder in folder.SubFolders)
      {                                         
    if (subFolder.Name.CompareTo("Forms") != 0)
        {
        jouas = GetItemsForFolderInt(subFolder);
       subFolder.Item["FilesCount"] = jouas;
       subFolder.Item.Update();    
    }
    }
    }                              
      }
    }               
    }
    }
    }
    }

     

    The code is still running only for Admin account and not for other users. Any suggestions on this.

    Thank you

  • Moss 2007 - Activated Feature working only for Admin Account

    Hi,

     

    I had created a feature and activated in the SharePoint site using the Admin account. The feature was to count the number of files under each sub folder. The feature got activated successfully. I tested the code under the Admin account, and it was working.
    I tried to test with other users, who had design and contribute access. But when the other users checked, the count was not showing. No errors were generated. This is the code I have used.

     

     public static void GetOpenItems()
      {
    using (SPSite site = new SPSite(Constants.url))
      {
    using (SPWeb currentweb = site.OpenWeb())
      {
    SPListCollection mylists = currentweb.GetListsOfType(SPBaseType.DocumentLibrary);
    for (int q = mylists.Count - 1; q >= 0; q--)                           
    {
    SPList list = mylists[q];
    
    if (!list.Hidden)
    {                              
    currentweb.AllowUnsafeUpdates = true;
    SPFolder folder = list.RootFolder;
    SPView curview = list.DefaultView;
    SPViewFieldCollection fieldCol = curview.ViewFields;
    if (!fieldCol.Exists("FilesCount"))
    {
    AddField("FilesCount", SPFieldType.Text, list.Fields);
    fieldCol.View.DefaultView = true;                                      
    curview.ViewFields.Add("FilesCount");
    curview.Update();                                  
    }
                                               
    int jouas = 0;                              
    if (folder != null && folder.Name.CompareTo("Forms") != 0)
    {
       foreach (SPFolder subFolder in folder.SubFolders)
      {                                         
    if (subFolder.Name.CompareTo("Forms") != 0)
        {
        jouas = GetItemsForFolderInt(subFolder);
       subFolder.Item["FilesCount"] = jouas;
       subFolder.Item.Update();    
    }
    }
    }                              
      }
    }               
    }
    }
    }

     

    These are the steps I used to install the feature from dev environment to Production environment.

     

    1) Copied the dll from GAC and pasted in Production server's GAC.

     

    2) Copied the relevant feature folders from 12 hive and pasted in the corresponding 12 hive of production server

     

    3) Used the Stsadm Install and Activate commands for the site.

     

    Is there anything else I should be doing?

     

    Please help.. I am not sure, what to do. The feature is working only for Admin account and not for users having other permissions.

     

    Thank you.

  • Creating pdf from byte array in c#

    W3bbo said:
    Sven Groot said:
    *snip*

    Sven, I can't help but read this thread with amusement. I think it's worth giving up, there's no hope for venkatzeus here; I get the impression he has absolutely zero hold on any of the concepts involved.

    Hi,

     

    I got the solution. One of the methods had a Url, which pointed to the pdf. I then used that with Process.start and invoked the pdf.

     

    Thanks Sven Groot and all for the help.

     

     

     

  • Creating pdf from byte array in c#

    Sven Groot said:
    venkatzeus said:
    *snip*

    What's a blob? I know what it is in database terms, but in C# terms it means nothing.

     

    What's the .Net type, the class name, of the web method's return value?

    In the webreference, when I add the reference, I get the following:

     

    WebMethodName ( id As int ) As BLOB
    

  • Creating pdf from byte array in c#

    Sven Groot said:
    venkatzeus said:
    *snip*

    Using the BinaryFormatter.Serialize method doesn't just write out the raw data of the object. It adds all kinds of stuff to ensure that the data can be safely deserialized again, like .Net type names. So the result of this method will definitely not be a valid PDF file.

     

    If the web service's return value indeed contains a PDF document in some format, you need to properly extract that data somehow. Without knowing the web services actual return type I can't help you with that. What is the type of the object returned by the web method?

    The Web Method returns a blob

  • Creating pdf from byte array in c#

    Sven Groot said:
    venkatzeus said:
    *snip*

    No, that's not what you're doing at all. You're creating a byte array, containing a serialized object graph (which is not valid PDF data), and then telling the browser to interpret that data as if it were a PDF.

     

    You are creating a PDF file, but the contents you supply for that file (the serialized object graph) is not a valid PDF document, so of course Adobe Reader can't open it. There is no magic process that can convert a serialized object graph to a PDF.

     

    What are you trying to do here exactly? What kind of data is that web service returning, and how is that data meant to be presented as a PDF?

    Hi,

    Thank you very much for the reply. Thanks for correcting me.

     

    The web service returns a pdf file as a serialized data, which has the return type as blob.

  • Creating pdf from byte array in c#

    Sven Groot said:
    venkatzeus said:
    *snip*

    There is no way that serializing an object could yield a valid PDF. How were you expecting this to become a PDF?

    I am converting to a byte array, and then using byte array to create a pdf.